Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
parse-events-test.c
Go to the documentation of this file.
1 
2 #include "parse-events.h"
3 #include "evsel.h"
4 #include "evlist.h"
5 #include "sysfs.h"
6 #include <linux/hw_breakpoint.h>
7 
8 #define TEST_ASSERT_VAL(text, cond) \
9 do { \
10  if (!(cond)) { \
11  pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
12  return -1; \
13  } \
14 } while (0)
15 
16 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
17  PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
18 
19 static int test__checkevent_tracepoint(struct perf_evlist *evlist)
20 {
21  struct perf_evsel *evsel = perf_evlist__first(evlist);
22 
23  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
24  TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
25  TEST_ASSERT_VAL("wrong sample_type",
26  PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
27  TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
28  return 0;
29 }
30 
31 static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
32 {
33  struct perf_evsel *evsel;
34 
35  TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
36 
37  list_for_each_entry(evsel, &evlist->entries, node) {
38  TEST_ASSERT_VAL("wrong type",
39  PERF_TYPE_TRACEPOINT == evsel->attr.type);
40  TEST_ASSERT_VAL("wrong sample_type",
41  PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
42  TEST_ASSERT_VAL("wrong sample_period",
43  1 == evsel->attr.sample_period);
44  }
45  return 0;
46 }
47 
48 static int test__checkevent_raw(struct perf_evlist *evlist)
49 {
50  struct perf_evsel *evsel = perf_evlist__first(evlist);
51 
52  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
53  TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
54  TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
55  return 0;
56 }
57 
58 static int test__checkevent_numeric(struct perf_evlist *evlist)
59 {
60  struct perf_evsel *evsel = perf_evlist__first(evlist);
61 
62  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
63  TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
64  TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
65  return 0;
66 }
67 
68 static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
69 {
70  struct perf_evsel *evsel = perf_evlist__first(evlist);
71 
72  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
73  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
74  TEST_ASSERT_VAL("wrong config",
75  PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
76  return 0;
77 }
78 
79 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
80 {
81  struct perf_evsel *evsel = perf_evlist__first(evlist);
82 
83  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
84  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
85  TEST_ASSERT_VAL("wrong config",
86  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
87  TEST_ASSERT_VAL("wrong period",
88  100000 == evsel->attr.sample_period);
89  TEST_ASSERT_VAL("wrong config1",
90  0 == evsel->attr.config1);
91  TEST_ASSERT_VAL("wrong config2",
92  1 == evsel->attr.config2);
93  return 0;
94 }
95 
96 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
97 {
98  struct perf_evsel *evsel = perf_evlist__first(evlist);
99 
100  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
101  TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
102  TEST_ASSERT_VAL("wrong config",
103  PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
104  return 0;
105 }
106 
107 static int test__checkevent_genhw(struct perf_evlist *evlist)
108 {
109  struct perf_evsel *evsel = perf_evlist__first(evlist);
110 
111  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
112  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
113  TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
114  return 0;
115 }
116 
117 static int test__checkevent_breakpoint(struct perf_evlist *evlist)
118 {
119  struct perf_evsel *evsel = perf_evlist__first(evlist);
120 
121  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
122  TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
123  TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
124  TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
125  evsel->attr.bp_type);
126  TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
127  evsel->attr.bp_len);
128  return 0;
129 }
130 
131 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
132 {
133  struct perf_evsel *evsel = perf_evlist__first(evlist);
134 
135  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
136  TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
137  TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
138  TEST_ASSERT_VAL("wrong bp_type",
139  HW_BREAKPOINT_X == evsel->attr.bp_type);
140  TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
141  return 0;
142 }
143 
144 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
145 {
146  struct perf_evsel *evsel = perf_evlist__first(evlist);
147 
148  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
149  TEST_ASSERT_VAL("wrong type",
150  PERF_TYPE_BREAKPOINT == evsel->attr.type);
151  TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
152  TEST_ASSERT_VAL("wrong bp_type",
153  HW_BREAKPOINT_R == evsel->attr.bp_type);
154  TEST_ASSERT_VAL("wrong bp_len",
155  HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
156  return 0;
157 }
158 
159 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
160 {
161  struct perf_evsel *evsel = perf_evlist__first(evlist);
162 
163  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
164  TEST_ASSERT_VAL("wrong type",
165  PERF_TYPE_BREAKPOINT == evsel->attr.type);
166  TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
167  TEST_ASSERT_VAL("wrong bp_type",
168  HW_BREAKPOINT_W == evsel->attr.bp_type);
169  TEST_ASSERT_VAL("wrong bp_len",
170  HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
171  return 0;
172 }
173 
174 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
175 {
176  struct perf_evsel *evsel = perf_evlist__first(evlist);
177 
178  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
179  TEST_ASSERT_VAL("wrong type",
180  PERF_TYPE_BREAKPOINT == evsel->attr.type);
181  TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
182  TEST_ASSERT_VAL("wrong bp_type",
183  (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
184  TEST_ASSERT_VAL("wrong bp_len",
185  HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
186  return 0;
187 }
188 
189 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
190 {
191  struct perf_evsel *evsel = perf_evlist__first(evlist);
192 
193  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
194  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
195  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
196  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
197 
198  return test__checkevent_tracepoint(evlist);
199 }
200 
201 static int
202 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
203 {
204  struct perf_evsel *evsel;
205 
206  TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
207 
208  list_for_each_entry(evsel, &evlist->entries, node) {
209  TEST_ASSERT_VAL("wrong exclude_user",
210  !evsel->attr.exclude_user);
211  TEST_ASSERT_VAL("wrong exclude_kernel",
212  evsel->attr.exclude_kernel);
213  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
214  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
215  }
216 
217  return test__checkevent_tracepoint_multi(evlist);
218 }
219 
220 static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
221 {
222  struct perf_evsel *evsel = perf_evlist__first(evlist);
223 
224  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
225  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
226  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
227  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
228 
229  return test__checkevent_raw(evlist);
230 }
231 
232 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
233 {
234  struct perf_evsel *evsel = perf_evlist__first(evlist);
235 
236  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
237  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
238  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
239  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
240 
241  return test__checkevent_numeric(evlist);
242 }
243 
244 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
245 {
246  struct perf_evsel *evsel = perf_evlist__first(evlist);
247 
248  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
249  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
250  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
251  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
252 
253  return test__checkevent_symbolic_name(evlist);
254 }
255 
256 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
257 {
258  struct perf_evsel *evsel = perf_evlist__first(evlist);
259 
260  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
261  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
262 
263  return test__checkevent_symbolic_name(evlist);
264 }
265 
266 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
267 {
268  struct perf_evsel *evsel = perf_evlist__first(evlist);
269 
270  TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
271  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
272 
273  return test__checkevent_symbolic_name(evlist);
274 }
275 
276 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
277 {
278  struct perf_evsel *evsel = perf_evlist__first(evlist);
279 
280  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
281  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
282  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
283  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
284 
285  return test__checkevent_symbolic_alias(evlist);
286 }
287 
288 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
289 {
290  struct perf_evsel *evsel = perf_evlist__first(evlist);
291 
292  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
293  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
294  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
295  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
296 
297  return test__checkevent_genhw(evlist);
298 }
299 
300 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
301 {
302  struct perf_evsel *evsel = perf_evlist__first(evlist);
303 
304 
305  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
306  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
307  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
308  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
309  TEST_ASSERT_VAL("wrong name",
310  !strcmp(perf_evsel__name(evsel), "mem:0:u"));
311 
312  return test__checkevent_breakpoint(evlist);
313 }
314 
315 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
316 {
317  struct perf_evsel *evsel = perf_evlist__first(evlist);
318 
319  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
320  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
321  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
322  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
323  TEST_ASSERT_VAL("wrong name",
324  !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
325 
326  return test__checkevent_breakpoint_x(evlist);
327 }
328 
329 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
330 {
331  struct perf_evsel *evsel = perf_evlist__first(evlist);
332 
333  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
334  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
335  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
336  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
337  TEST_ASSERT_VAL("wrong name",
338  !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
339 
340  return test__checkevent_breakpoint_r(evlist);
341 }
342 
343 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
344 {
345  struct perf_evsel *evsel = perf_evlist__first(evlist);
346 
347  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
348  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
349  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
350  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
351  TEST_ASSERT_VAL("wrong name",
352  !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
353 
354  return test__checkevent_breakpoint_w(evlist);
355 }
356 
357 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
358 {
359  struct perf_evsel *evsel = perf_evlist__first(evlist);
360 
361  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
362  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
363  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
364  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
365  TEST_ASSERT_VAL("wrong name",
366  !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
367 
368  return test__checkevent_breakpoint_rw(evlist);
369 }
370 
371 static int test__checkevent_pmu(struct perf_evlist *evlist)
372 {
373 
374  struct perf_evsel *evsel = perf_evlist__first(evlist);
375 
376  TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
377  TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
378  TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
379  TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
380  TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
381  TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
382 
383  return 0;
384 }
385 
386 static int test__checkevent_list(struct perf_evlist *evlist)
387 {
388  struct perf_evsel *evsel = perf_evlist__first(evlist);
389 
390  TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
391 
392  /* r1 */
393  TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
394  TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
395  TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
396  TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
397  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
398  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
399  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
400  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
401 
402  /* syscalls:sys_enter_open:k */
403  evsel = perf_evsel__next(evsel);
404  TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
405  TEST_ASSERT_VAL("wrong sample_type",
406  PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
407  TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
408  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
409  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
410  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
411  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
412 
413  /* 1:1:hp */
414  evsel = perf_evsel__next(evsel);
415  TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
416  TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
417  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
418  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
419  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
420  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
421 
422  return 0;
423 }
424 
425 static int test__checkevent_pmu_name(struct perf_evlist *evlist)
426 {
427  struct perf_evsel *evsel = perf_evlist__first(evlist);
428 
429  /* cpu/config=1,name=krava/u */
430  TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
431  TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
432  TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
433  TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
434 
435  /* cpu/config=2/u" */
436  evsel = perf_evsel__next(evsel);
437  TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
438  TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
439  TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
440  TEST_ASSERT_VAL("wrong name",
441  !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
442 
443  return 0;
444 }
445 
446 static int test__checkterms_simple(struct list_head *terms)
447 {
448  struct parse_events__term *term;
449 
450  /* config=10 */
451  term = list_entry(terms->next, struct parse_events__term, list);
452  TEST_ASSERT_VAL("wrong type term",
454  TEST_ASSERT_VAL("wrong type val",
456  TEST_ASSERT_VAL("wrong val", term->val.num == 10);
457  TEST_ASSERT_VAL("wrong config", !term->config);
458 
459  /* config1 */
460  term = list_entry(term->list.next, struct parse_events__term, list);
461  TEST_ASSERT_VAL("wrong type term",
463  TEST_ASSERT_VAL("wrong type val",
465  TEST_ASSERT_VAL("wrong val", term->val.num == 1);
466  TEST_ASSERT_VAL("wrong config", !term->config);
467 
468  /* config2=3 */
469  term = list_entry(term->list.next, struct parse_events__term, list);
470  TEST_ASSERT_VAL("wrong type term",
472  TEST_ASSERT_VAL("wrong type val",
474  TEST_ASSERT_VAL("wrong val", term->val.num == 3);
475  TEST_ASSERT_VAL("wrong config", !term->config);
476 
477  /* umask=1*/
478  term = list_entry(term->list.next, struct parse_events__term, list);
479  TEST_ASSERT_VAL("wrong type term",
481  TEST_ASSERT_VAL("wrong type val",
483  TEST_ASSERT_VAL("wrong val", term->val.num == 1);
484  TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
485 
486  return 0;
487 }
488 
489 static int test__group1(struct perf_evlist *evlist)
490 {
491  struct perf_evsel *evsel, *leader;
492 
493  TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
494 
495  /* instructions:k */
496  evsel = leader = perf_evlist__first(evlist);
497  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
498  TEST_ASSERT_VAL("wrong config",
499  PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
500  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
501  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
502  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
503  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
504  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
505  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
506  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
507 
508  /* cycles:upp */
509  evsel = perf_evsel__next(evsel);
510  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
511  TEST_ASSERT_VAL("wrong config",
512  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
513  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
514  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
515  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
516  /* use of precise requires exclude_guest */
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 == 2);
520  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
521 
522  return 0;
523 }
524 
525 static int test__group2(struct perf_evlist *evlist)
526 {
527  struct perf_evsel *evsel, *leader;
528 
529  TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
530 
531  /* faults + :ku modifier */
532  evsel = leader = perf_evlist__first(evlist);
533  TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
534  TEST_ASSERT_VAL("wrong config",
535  PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
536  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
537  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
538  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
539  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
540  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
541  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
542  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
543 
544  /* cache-references + :u modifier */
545  evsel = perf_evsel__next(evsel);
546  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
547  TEST_ASSERT_VAL("wrong config",
548  PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
549  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
550  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
551  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
552  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
553  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
554  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
555  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
556 
557  /* cycles:k */
558  evsel = perf_evsel__next(evsel);
559  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
560  TEST_ASSERT_VAL("wrong config",
561  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
562  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
563  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
564  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
565  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
566  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
567  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
568  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
569 
570  return 0;
571 }
572 
573 static int test__group3(struct perf_evlist *evlist __maybe_unused)
574 {
575  struct perf_evsel *evsel, *leader;
576 
577  TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
578 
579  /* group1 syscalls:sys_enter_open:H */
580  evsel = leader = perf_evlist__first(evlist);
581  TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
582  TEST_ASSERT_VAL("wrong sample_type",
583  PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
584  TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
585  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
586  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
587  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
588  TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
589  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
590  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
591  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
592  TEST_ASSERT_VAL("wrong group name",
593  !strcmp(leader->group_name, "group1"));
594 
595  /* group1 cycles:kppp */
596  evsel = perf_evsel__next(evsel);
597  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
598  TEST_ASSERT_VAL("wrong config",
599  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
600  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
601  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
602  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
603  /* use of precise requires exclude_guest */
604  TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
605  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
606  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
607  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
608  TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
609 
610  /* group2 cycles + G modifier */
611  evsel = leader = perf_evsel__next(evsel);
612  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
613  TEST_ASSERT_VAL("wrong config",
614  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
615  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
616  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
617  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
618  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
619  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
620  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
621  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
622  TEST_ASSERT_VAL("wrong group name",
623  !strcmp(leader->group_name, "group2"));
624 
625  /* group2 1:3 + G modifier */
626  evsel = perf_evsel__next(evsel);
627  TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
628  TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
629  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
630  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
631  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
632  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
633  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
634  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
635  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
636 
637  /* instructions:u */
638  evsel = perf_evsel__next(evsel);
639  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
640  TEST_ASSERT_VAL("wrong config",
641  PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
642  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
643  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
644  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
645  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
646  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
647  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
648  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
649 
650  return 0;
651 }
652 
653 static int test__group4(struct perf_evlist *evlist __maybe_unused)
654 {
655  struct perf_evsel *evsel, *leader;
656 
657  TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
658 
659  /* cycles:u + p */
660  evsel = leader = perf_evlist__first(evlist);
661  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
662  TEST_ASSERT_VAL("wrong config",
663  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
664  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
665  TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
666  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
667  /* use of precise requires exclude_guest */
668  TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
669  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
670  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
671  TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
672  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
673 
674  /* instructions:kp + p */
675  evsel = perf_evsel__next(evsel);
676  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
677  TEST_ASSERT_VAL("wrong config",
678  PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
679  TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
680  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
681  TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
682  /* use of precise requires exclude_guest */
683  TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
684  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
685  TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
686  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
687 
688  return 0;
689 }
690 
691 static int test__group5(struct perf_evlist *evlist __maybe_unused)
692 {
693  struct perf_evsel *evsel, *leader;
694 
695  TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
696 
697  /* cycles + G */
698  evsel = leader = perf_evlist__first(evlist);
699  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
700  TEST_ASSERT_VAL("wrong config",
701  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
702  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
703  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
704  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
705  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
706  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
707  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
708  TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
709  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
710 
711  /* instructions + G */
712  evsel = perf_evsel__next(evsel);
713  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
714  TEST_ASSERT_VAL("wrong config",
715  PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
716  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
717  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
718  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
719  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
720  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
721  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
722  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
723 
724  /* cycles:G */
725  evsel = leader = perf_evsel__next(evsel);
726  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
727  TEST_ASSERT_VAL("wrong config",
728  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
729  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
730  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
731  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
732  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
733  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
734  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
735  TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
736  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
737 
738  /* instructions:G */
739  evsel = perf_evsel__next(evsel);
740  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
741  TEST_ASSERT_VAL("wrong config",
742  PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
743  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
744  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
745  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
746  TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
747  TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
748  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
749  TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
750 
751  /* cycles */
752  evsel = perf_evsel__next(evsel);
753  TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
754  TEST_ASSERT_VAL("wrong config",
755  PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
756  TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
757  TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
758  TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
759  TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
760  TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
761  TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
762  TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
763 
764  return 0;
765 }
766 
768  const char *name;
770  int (*check)(struct perf_evlist *evlist);
771 };
772 
773 static struct test__event_st test__events[] = {
774  [0] = {
775  .name = "syscalls:sys_enter_open",
776  .check = test__checkevent_tracepoint,
777  },
778  [1] = {
779  .name = "syscalls:*",
780  .check = test__checkevent_tracepoint_multi,
781  },
782  [2] = {
783  .name = "r1a",
784  .check = test__checkevent_raw,
785  },
786  [3] = {
787  .name = "1:1",
788  .check = test__checkevent_numeric,
789  },
790  [4] = {
791  .name = "instructions",
792  .check = test__checkevent_symbolic_name,
793  },
794  [5] = {
795  .name = "cycles/period=100000,config2/",
796  .check = test__checkevent_symbolic_name_config,
797  },
798  [6] = {
799  .name = "faults",
800  .check = test__checkevent_symbolic_alias,
801  },
802  [7] = {
803  .name = "L1-dcache-load-miss",
804  .check = test__checkevent_genhw,
805  },
806  [8] = {
807  .name = "mem:0",
808  .check = test__checkevent_breakpoint,
809  },
810  [9] = {
811  .name = "mem:0:x",
812  .check = test__checkevent_breakpoint_x,
813  },
814  [10] = {
815  .name = "mem:0:r",
816  .check = test__checkevent_breakpoint_r,
817  },
818  [11] = {
819  .name = "mem:0:w",
820  .check = test__checkevent_breakpoint_w,
821  },
822  [12] = {
823  .name = "syscalls:sys_enter_open:k",
824  .check = test__checkevent_tracepoint_modifier,
825  },
826  [13] = {
827  .name = "syscalls:*:u",
828  .check = test__checkevent_tracepoint_multi_modifier,
829  },
830  [14] = {
831  .name = "r1a:kp",
832  .check = test__checkevent_raw_modifier,
833  },
834  [15] = {
835  .name = "1:1:hp",
836  .check = test__checkevent_numeric_modifier,
837  },
838  [16] = {
839  .name = "instructions:h",
840  .check = test__checkevent_symbolic_name_modifier,
841  },
842  [17] = {
843  .name = "faults:u",
844  .check = test__checkevent_symbolic_alias_modifier,
845  },
846  [18] = {
847  .name = "L1-dcache-load-miss:kp",
848  .check = test__checkevent_genhw_modifier,
849  },
850  [19] = {
851  .name = "mem:0:u",
852  .check = test__checkevent_breakpoint_modifier,
853  },
854  [20] = {
855  .name = "mem:0:x:k",
856  .check = test__checkevent_breakpoint_x_modifier,
857  },
858  [21] = {
859  .name = "mem:0:r:hp",
860  .check = test__checkevent_breakpoint_r_modifier,
861  },
862  [22] = {
863  .name = "mem:0:w:up",
864  .check = test__checkevent_breakpoint_w_modifier,
865  },
866  [23] = {
867  .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
868  .check = test__checkevent_list,
869  },
870  [24] = {
871  .name = "instructions:G",
872  .check = test__checkevent_exclude_host_modifier,
873  },
874  [25] = {
875  .name = "instructions:H",
876  .check = test__checkevent_exclude_guest_modifier,
877  },
878  [26] = {
879  .name = "mem:0:rw",
880  .check = test__checkevent_breakpoint_rw,
881  },
882  [27] = {
883  .name = "mem:0:rw:kp",
884  .check = test__checkevent_breakpoint_rw_modifier,
885  },
886  [28] = {
887  .name = "{instructions:k,cycles:upp}",
888  .check = test__group1,
889  },
890  [29] = {
891  .name = "{faults:k,cache-references}:u,cycles:k",
892  .check = test__group2,
893  },
894  [30] = {
895  .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
896  .check = test__group3,
897  },
898  [31] = {
899  .name = "{cycles:u,instructions:kp}:p",
900  .check = test__group4,
901  },
902  [32] = {
903  .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
904  .check = test__group5,
905  },
906 };
907 
908 static struct test__event_st test__events_pmu[] = {
909  [0] = {
910  .name = "cpu/config=10,config1,config2=3,period=1000/u",
911  .check = test__checkevent_pmu,
912  },
913  [1] = {
914  .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
915  .check = test__checkevent_pmu_name,
916  },
917 };
918 
919 struct test__term {
920  const char *str;
922  int (*check)(struct list_head *terms);
923 };
924 
925 static struct test__term test__terms[] = {
926  [0] = {
927  .str = "config=10,config1,config2=3,umask=1",
928  .check = test__checkterms_simple,
929  },
930 };
931 
932 static int test_event(struct test__event_st *e)
933 {
934  struct perf_evlist *evlist;
935  int ret;
936 
937  evlist = perf_evlist__new(NULL, NULL);
938  if (evlist == NULL)
939  return -ENOMEM;
940 
941  ret = parse_events(evlist, e->name, 0);
942  if (ret) {
943  pr_debug("failed to parse event '%s', err %d\n",
944  e->name, ret);
945  return ret;
946  }
947 
948  ret = e->check(evlist);
949  perf_evlist__delete(evlist);
950 
951  return ret;
952 }
953 
954 static int test_events(struct test__event_st *events, unsigned cnt)
955 {
956  int ret1, ret2 = 0;
957  unsigned i;
958 
959  for (i = 0; i < cnt; i++) {
960  struct test__event_st *e = &events[i];
961 
962  pr_debug("running test %d '%s'\n", i, e->name);
963  ret1 = test_event(e);
964  if (ret1)
965  ret2 = ret1;
966  }
967 
968  return ret2;
969 }
970 
971 static int test_term(struct test__term *t)
972 {
973  struct list_head *terms;
974  int ret;
975 
976  terms = malloc(sizeof(*terms));
977  if (!terms)
978  return -ENOMEM;
979 
980  INIT_LIST_HEAD(terms);
981 
982  ret = parse_events_terms(terms, t->str);
983  if (ret) {
984  pr_debug("failed to parse terms '%s', err %d\n",
985  t->str , ret);
986  return ret;
987  }
988 
989  ret = t->check(terms);
991 
992  return ret;
993 }
994 
995 static int test_terms(struct test__term *terms, unsigned cnt)
996 {
997  int ret = 0;
998  unsigned i;
999 
1000  for (i = 0; i < cnt; i++) {
1001  struct test__term *t = &terms[i];
1002 
1003  pr_debug("running test %d '%s'\n", i, t->str);
1004  ret = test_term(t);
1005  if (ret)
1006  break;
1007  }
1008 
1009  return ret;
1010 }
1011 
1012 static int test_pmu(void)
1013 {
1014  struct stat st;
1015  char path[PATH_MAX];
1016  int ret;
1017 
1018  snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1020 
1021  ret = stat(path, &st);
1022  if (ret)
1023  pr_debug("omitting PMU cpu tests\n");
1024  return !ret;
1025 }
1026 
1028 {
1029  int ret1, ret2 = 0;
1030 
1031 #define TEST_EVENTS(tests) \
1032 do { \
1033  ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1034  if (!ret2) \
1035  ret2 = ret1; \
1036 } while (0)
1037 
1038  TEST_EVENTS(test__events);
1039 
1040  if (test_pmu())
1041  TEST_EVENTS(test__events_pmu);
1042 
1043  ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1044  if (!ret2)
1045  ret2 = ret1;
1046 
1047  return ret2;
1048 }