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