blob: 127d648cc5488e6b1216ce3d3428c7a69e5157fb [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 Olsaf50246e2012-05-21 09:12:49 +0200516struct test__event_st {
517 const char *name;
518 __u32 type;
519 int (*check)(struct perf_evlist *evlist);
520};
521
522static struct test__event_st test__events[] = {
523 [0] = {
524 .name = "syscalls:sys_enter_open",
525 .check = test__checkevent_tracepoint,
526 },
527 [1] = {
528 .name = "syscalls:*",
529 .check = test__checkevent_tracepoint_multi,
530 },
531 [2] = {
532 .name = "r1a",
533 .check = test__checkevent_raw,
534 },
535 [3] = {
536 .name = "1:1",
537 .check = test__checkevent_numeric,
538 },
539 [4] = {
540 .name = "instructions",
541 .check = test__checkevent_symbolic_name,
542 },
543 [5] = {
544 .name = "cycles/period=100000,config2/",
545 .check = test__checkevent_symbolic_name_config,
546 },
547 [6] = {
548 .name = "faults",
549 .check = test__checkevent_symbolic_alias,
550 },
551 [7] = {
552 .name = "L1-dcache-load-miss",
553 .check = test__checkevent_genhw,
554 },
555 [8] = {
556 .name = "mem:0",
557 .check = test__checkevent_breakpoint,
558 },
559 [9] = {
560 .name = "mem:0:x",
561 .check = test__checkevent_breakpoint_x,
562 },
563 [10] = {
564 .name = "mem:0:r",
565 .check = test__checkevent_breakpoint_r,
566 },
567 [11] = {
568 .name = "mem:0:w",
569 .check = test__checkevent_breakpoint_w,
570 },
571 [12] = {
572 .name = "syscalls:sys_enter_open:k",
573 .check = test__checkevent_tracepoint_modifier,
574 },
575 [13] = {
576 .name = "syscalls:*:u",
577 .check = test__checkevent_tracepoint_multi_modifier,
578 },
579 [14] = {
580 .name = "r1a:kp",
581 .check = test__checkevent_raw_modifier,
582 },
583 [15] = {
584 .name = "1:1:hp",
585 .check = test__checkevent_numeric_modifier,
586 },
587 [16] = {
588 .name = "instructions:h",
589 .check = test__checkevent_symbolic_name_modifier,
590 },
591 [17] = {
592 .name = "faults:u",
593 .check = test__checkevent_symbolic_alias_modifier,
594 },
595 [18] = {
596 .name = "L1-dcache-load-miss:kp",
597 .check = test__checkevent_genhw_modifier,
598 },
599 [19] = {
600 .name = "mem:0:u",
601 .check = test__checkevent_breakpoint_modifier,
602 },
603 [20] = {
604 .name = "mem:0:x:k",
605 .check = test__checkevent_breakpoint_x_modifier,
606 },
607 [21] = {
608 .name = "mem:0:r:hp",
609 .check = test__checkevent_breakpoint_r_modifier,
610 },
611 [22] = {
612 .name = "mem:0:w:up",
613 .check = test__checkevent_breakpoint_w_modifier,
614 },
615 [23] = {
616 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
617 .check = test__checkevent_list,
618 },
619 [24] = {
620 .name = "instructions:G",
621 .check = test__checkevent_exclude_host_modifier,
622 },
623 [25] = {
624 .name = "instructions:H",
625 .check = test__checkevent_exclude_guest_modifier,
626 },
Jiri Olsa75827322012-06-29 09:22:54 +0200627 [26] = {
628 .name = "mem:0:rw",
629 .check = test__checkevent_breakpoint_rw,
630 },
631 [27] = {
632 .name = "mem:0:rw:kp",
633 .check = test__checkevent_breakpoint_rw_modifier,
634 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200635};
636
Jiri Olsaf50246e2012-05-21 09:12:49 +0200637static struct test__event_st test__events_pmu[] = {
638 [0] = {
639 .name = "cpu/config=10,config1,config2=3,period=1000/u",
640 .check = test__checkevent_pmu,
641 },
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200642 [1] = {
643 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
644 .check = test__checkevent_pmu_name,
645 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200646};
647
Jiri Olsa44293922012-06-15 14:31:42 +0800648struct test__term {
649 const char *str;
650 __u32 type;
651 int (*check)(struct list_head *terms);
652};
653
654static struct test__term test__terms[] = {
655 [0] = {
656 .str = "config=10,config1,config2=3,umask=1",
657 .check = test__checkterms_simple,
658 },
659};
660
661#define TEST__TERMS_CNT (sizeof(test__terms) / \
662 sizeof(struct test__term))
663
664static int test_event(struct test__event_st *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +0200665{
666 struct perf_evlist *evlist;
667 int ret;
668
669 evlist = perf_evlist__new(NULL, NULL);
670 if (evlist == NULL)
671 return -ENOMEM;
672
673 ret = parse_events(evlist, e->name, 0);
674 if (ret) {
675 pr_debug("failed to parse event '%s', err %d\n",
676 e->name, ret);
677 return ret;
678 }
679
680 ret = e->check(evlist);
681 perf_evlist__delete(evlist);
682
683 return ret;
684}
685
686static int test_events(struct test__event_st *events, unsigned cnt)
687{
688 int ret = 0;
689 unsigned i;
690
691 for (i = 0; i < cnt; i++) {
692 struct test__event_st *e = &events[i];
693
694 pr_debug("running test %d '%s'\n", i, e->name);
Jiri Olsa44293922012-06-15 14:31:42 +0800695 ret = test_event(e);
696 if (ret)
697 break;
698 }
699
700 return ret;
701}
702
703static int test_term(struct test__term *t)
704{
705 struct list_head *terms;
706 int ret;
707
708 terms = malloc(sizeof(*terms));
709 if (!terms)
710 return -ENOMEM;
711
712 INIT_LIST_HEAD(terms);
713
714 ret = parse_events_terms(terms, t->str);
715 if (ret) {
716 pr_debug("failed to parse terms '%s', err %d\n",
717 t->str , ret);
718 return ret;
719 }
720
721 ret = t->check(terms);
722 parse_events__free_terms(terms);
723
724 return ret;
725}
726
727static int test_terms(struct test__term *terms, unsigned cnt)
728{
729 int ret = 0;
730 unsigned i;
731
732 for (i = 0; i < cnt; i++) {
733 struct test__term *t = &terms[i];
734
735 pr_debug("running test %d '%s'\n", i, t->str);
736 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200737 if (ret)
738 break;
739 }
740
741 return ret;
742}
743
744static int test_pmu(void)
745{
746 struct stat st;
747 char path[PATH_MAX];
748 int ret;
749
750 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
751 sysfs_find_mountpoint());
752
753 ret = stat(path, &st);
754 if (ret)
755 pr_debug("ommiting PMU cpu tests\n");
756 return !ret;
757}
758
759int parse_events__test(void)
760{
761 int ret;
762
Jiri Olsaebf124f2012-07-04 00:00:47 +0200763#define TEST_EVENTS(tests) \
764do { \
765 ret = test_events(tests, ARRAY_SIZE(tests)); \
766 if (ret) \
767 return ret; \
768} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +0800769
Jiri Olsaebf124f2012-07-04 00:00:47 +0200770 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +0800771
Jiri Olsaebf124f2012-07-04 00:00:47 +0200772 if (test_pmu())
773 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +0800774
Jiri Olsaebf124f2012-07-04 00:00:47 +0200775 return test_terms(test__terms, ARRAY_SIZE(test__terms));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200776}