blob: bf055ce1916e523908a024c7d7b2e0b5d9b79e10 [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{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030021 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020022
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",
Jiri Olsa30f31c02012-08-01 14:48:58 +020026 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020027 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
28 return 0;
29}
30
31static 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",
Jiri Olsa30f31c02012-08-01 14:48:58 +020041 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020042 TEST_ASSERT_VAL("wrong sample_period",
43 1 == evsel->attr.sample_period);
44 }
45 return 0;
46}
47
48static int test__checkevent_raw(struct perf_evlist *evlist)
49{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030050 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020051
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
58static int test__checkevent_numeric(struct perf_evlist *evlist)
59{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030060 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020061
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
68static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
69{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030070 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020071
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
79static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
80{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030081 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020082
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
96static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
97{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030098 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020099
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
107static int test__checkevent_genhw(struct perf_evlist *evlist)
108{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300109 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200110
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
117static int test__checkevent_breakpoint(struct perf_evlist *evlist)
118{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300119 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200120
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
131static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
132{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300133 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200134
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
144static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
145{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300146 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200147
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
159static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
160{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300161 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200162
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
Jiri Olsa75827322012-06-29 09:22:54 +0200174static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
175{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300176 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200177
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
Jiri Olsaf50246e2012-05-21 09:12:49 +0200189static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
190{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300191 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200192
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
201static int
202test__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
220static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
221{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300222 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200223
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
232static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
233{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300234 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200235
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
244static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
245{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300246 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200247
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
256static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
257{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300258 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200259
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
266static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
267{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300268 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200269
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
276static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
277{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300278 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200279
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
288static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
289{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300290 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200291
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
300static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
301{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300302 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200303
304 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
305 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
306 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
307 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200308 TEST_ASSERT_VAL("wrong name",
309 !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200310
311 return test__checkevent_breakpoint(evlist);
312}
313
314static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
315{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300316 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200317
318 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
319 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
320 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
321 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200322 TEST_ASSERT_VAL("wrong name",
323 !strcmp(perf_evsel__name(evsel), "mem:0x0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200324
325 return test__checkevent_breakpoint_x(evlist);
326}
327
328static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
329{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300330 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200331
332 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
333 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
334 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
335 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200336 TEST_ASSERT_VAL("wrong name",
337 !strcmp(perf_evsel__name(evsel), "mem:0x0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200338
339 return test__checkevent_breakpoint_r(evlist);
340}
341
342static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
343{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300344 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200345
346 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
347 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
348 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
349 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200350 TEST_ASSERT_VAL("wrong name",
351 !strcmp(perf_evsel__name(evsel), "mem:0x0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200352
353 return test__checkevent_breakpoint_w(evlist);
354}
355
Jiri Olsa75827322012-06-29 09:22:54 +0200356static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
357{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300358 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200359
360 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
361 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
362 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
363 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200364 TEST_ASSERT_VAL("wrong name",
365 !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200366
367 return test__checkevent_breakpoint_rw(evlist);
368}
369
Jiri Olsaf50246e2012-05-21 09:12:49 +0200370static int test__checkevent_pmu(struct perf_evlist *evlist)
371{
372
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300373 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200374
375 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
376 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
377 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
378 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
379 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
380 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
381
382 return 0;
383}
384
385static int test__checkevent_list(struct perf_evlist *evlist)
386{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300387 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200388
389 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
390
391 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200392 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
393 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
394 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
395 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
396 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
397 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
398 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
399 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
400
401 /* syscalls:sys_enter_open:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300402 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200403 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
404 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200405 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200406 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
407 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
408 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
409 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
410 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
411
412 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300413 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200414 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
415 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
416 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
417 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
418 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
419 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
420
421 return 0;
422}
423
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200424static int test__checkevent_pmu_name(struct perf_evlist *evlist)
425{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300426 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200427
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200428 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200429 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
430 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
431 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300432 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200433
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200434 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300435 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200436 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
437 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
438 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200439 TEST_ASSERT_VAL("wrong name",
440 !strcmp(perf_evsel__name(evsel), "raw 0x2:u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200441
442 return 0;
443}
444
Jiri Olsa44293922012-06-15 14:31:42 +0800445static int test__checkterms_simple(struct list_head *terms)
446{
447 struct parse_events__term *term;
448
449 /* config=10 */
450 term = list_entry(terms->next, struct parse_events__term, list);
451 TEST_ASSERT_VAL("wrong type term",
452 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
453 TEST_ASSERT_VAL("wrong type val",
454 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
455 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
456 TEST_ASSERT_VAL("wrong config", !term->config);
457
458 /* config1 */
459 term = list_entry(term->list.next, struct parse_events__term, list);
460 TEST_ASSERT_VAL("wrong type term",
461 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
462 TEST_ASSERT_VAL("wrong type val",
463 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
464 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
465 TEST_ASSERT_VAL("wrong config", !term->config);
466
467 /* config2=3 */
468 term = list_entry(term->list.next, struct parse_events__term, list);
469 TEST_ASSERT_VAL("wrong type term",
470 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
471 TEST_ASSERT_VAL("wrong type val",
472 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
473 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
474 TEST_ASSERT_VAL("wrong config", !term->config);
475
476 /* umask=1*/
477 term = list_entry(term->list.next, struct parse_events__term, list);
478 TEST_ASSERT_VAL("wrong type term",
479 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
480 TEST_ASSERT_VAL("wrong type val",
481 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
482 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
483 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
484
485 return 0;
486}
487
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200488static int test__group1(struct perf_evlist *evlist)
489{
490 struct perf_evsel *evsel, *leader;
491
492 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
493
494 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300495 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200496 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
497 TEST_ASSERT_VAL("wrong config",
498 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
499 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
500 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
501 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
502 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
503 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
504 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
505 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
506
507 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300508 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200509 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
510 TEST_ASSERT_VAL("wrong config",
511 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
512 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
513 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
514 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
515 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
516 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
517 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
518 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
519
520 return 0;
521}
522
523static int test__group2(struct perf_evlist *evlist)
524{
525 struct perf_evsel *evsel, *leader;
526
527 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
528
529 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300530 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200531 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
532 TEST_ASSERT_VAL("wrong config",
533 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
534 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
535 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
536 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
537 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
538 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
539 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
540 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
541
542 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300543 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200544 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
545 TEST_ASSERT_VAL("wrong config",
546 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
547 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
548 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
549 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
550 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
551 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
552 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
553 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
554
555 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300556 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200557 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
558 TEST_ASSERT_VAL("wrong config",
559 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
560 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
561 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
562 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
563 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
564 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
565 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
566 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
567
568 return 0;
569}
570
571static int test__group3(struct perf_evlist *evlist __used)
572{
573 struct perf_evsel *evsel, *leader;
574
575 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
576
577 /* group1 syscalls:sys_enter_open:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300578 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200579 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
580 TEST_ASSERT_VAL("wrong sample_type",
581 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
582 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
583 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
584 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
585 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
586 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
587 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
588 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
589 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
590 TEST_ASSERT_VAL("wrong group name",
591 !strcmp(leader->group_name, "group1"));
592
593 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300594 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200595 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
596 TEST_ASSERT_VAL("wrong config",
597 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
598 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
599 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
600 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
601 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
602 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
603 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
604 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
605 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
606
607 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300608 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200609 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
610 TEST_ASSERT_VAL("wrong config",
611 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
612 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
613 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
614 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
615 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
616 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
617 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
618 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
619 TEST_ASSERT_VAL("wrong group name",
620 !strcmp(leader->group_name, "group2"));
621
622 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300623 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200624 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
625 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
626 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
627 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
628 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
629 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
630 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
631 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
632 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
633
634 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300635 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200636 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
637 TEST_ASSERT_VAL("wrong config",
638 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
639 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
640 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
641 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
642 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
643 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
644 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
645 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
646
647 return 0;
648}
649
650static int test__group4(struct perf_evlist *evlist __used)
651{
652 struct perf_evsel *evsel, *leader;
653
654 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
655
656 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300657 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
659 TEST_ASSERT_VAL("wrong config",
660 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
661 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
662 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
663 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
664 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
665 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
666 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
667 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
668 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
669
670 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300671 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200672 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
673 TEST_ASSERT_VAL("wrong config",
674 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
675 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
676 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
677 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
678 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
679 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
680 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
681 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
682
683 return 0;
684}
685
686static int test__group5(struct perf_evlist *evlist __used)
687{
688 struct perf_evsel *evsel, *leader;
689
690 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
691
692 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300693 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200694 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
695 TEST_ASSERT_VAL("wrong config",
696 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
697 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
698 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
699 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
700 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
701 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
702 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
703 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
704 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
705
706 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300707 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200708 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
709 TEST_ASSERT_VAL("wrong config",
710 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
711 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
712 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
713 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
714 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
715 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
716 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
717 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
718
719 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300720 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200721 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
722 TEST_ASSERT_VAL("wrong config",
723 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
724 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
725 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
726 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
727 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
728 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
729 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
730 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
731 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
732
733 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300734 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200735 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
736 TEST_ASSERT_VAL("wrong config",
737 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
738 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
739 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
740 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
741 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
742 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
743 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
744 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
745
746 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300747 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200748 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
749 TEST_ASSERT_VAL("wrong config",
750 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
751 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
752 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
753 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
754 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
755 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
756 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
757 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
758
759 return 0;
760}
761
Jiri Olsaf50246e2012-05-21 09:12:49 +0200762struct test__event_st {
763 const char *name;
764 __u32 type;
765 int (*check)(struct perf_evlist *evlist);
766};
767
768static struct test__event_st test__events[] = {
769 [0] = {
770 .name = "syscalls:sys_enter_open",
771 .check = test__checkevent_tracepoint,
772 },
773 [1] = {
774 .name = "syscalls:*",
775 .check = test__checkevent_tracepoint_multi,
776 },
777 [2] = {
778 .name = "r1a",
779 .check = test__checkevent_raw,
780 },
781 [3] = {
782 .name = "1:1",
783 .check = test__checkevent_numeric,
784 },
785 [4] = {
786 .name = "instructions",
787 .check = test__checkevent_symbolic_name,
788 },
789 [5] = {
790 .name = "cycles/period=100000,config2/",
791 .check = test__checkevent_symbolic_name_config,
792 },
793 [6] = {
794 .name = "faults",
795 .check = test__checkevent_symbolic_alias,
796 },
797 [7] = {
798 .name = "L1-dcache-load-miss",
799 .check = test__checkevent_genhw,
800 },
801 [8] = {
802 .name = "mem:0",
803 .check = test__checkevent_breakpoint,
804 },
805 [9] = {
806 .name = "mem:0:x",
807 .check = test__checkevent_breakpoint_x,
808 },
809 [10] = {
810 .name = "mem:0:r",
811 .check = test__checkevent_breakpoint_r,
812 },
813 [11] = {
814 .name = "mem:0:w",
815 .check = test__checkevent_breakpoint_w,
816 },
817 [12] = {
818 .name = "syscalls:sys_enter_open:k",
819 .check = test__checkevent_tracepoint_modifier,
820 },
821 [13] = {
822 .name = "syscalls:*:u",
823 .check = test__checkevent_tracepoint_multi_modifier,
824 },
825 [14] = {
826 .name = "r1a:kp",
827 .check = test__checkevent_raw_modifier,
828 },
829 [15] = {
830 .name = "1:1:hp",
831 .check = test__checkevent_numeric_modifier,
832 },
833 [16] = {
834 .name = "instructions:h",
835 .check = test__checkevent_symbolic_name_modifier,
836 },
837 [17] = {
838 .name = "faults:u",
839 .check = test__checkevent_symbolic_alias_modifier,
840 },
841 [18] = {
842 .name = "L1-dcache-load-miss:kp",
843 .check = test__checkevent_genhw_modifier,
844 },
845 [19] = {
846 .name = "mem:0:u",
847 .check = test__checkevent_breakpoint_modifier,
848 },
849 [20] = {
850 .name = "mem:0:x:k",
851 .check = test__checkevent_breakpoint_x_modifier,
852 },
853 [21] = {
854 .name = "mem:0:r:hp",
855 .check = test__checkevent_breakpoint_r_modifier,
856 },
857 [22] = {
858 .name = "mem:0:w:up",
859 .check = test__checkevent_breakpoint_w_modifier,
860 },
861 [23] = {
862 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
863 .check = test__checkevent_list,
864 },
865 [24] = {
866 .name = "instructions:G",
867 .check = test__checkevent_exclude_host_modifier,
868 },
869 [25] = {
870 .name = "instructions:H",
871 .check = test__checkevent_exclude_guest_modifier,
872 },
Jiri Olsa75827322012-06-29 09:22:54 +0200873 [26] = {
874 .name = "mem:0:rw",
875 .check = test__checkevent_breakpoint_rw,
876 },
877 [27] = {
878 .name = "mem:0:rw:kp",
879 .check = test__checkevent_breakpoint_rw_modifier,
880 },
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200881 [28] = {
882 .name = "{instructions:k,cycles:upp}",
883 .check = test__group1,
884 },
885 [29] = {
886 .name = "{faults:k,cache-references}:u,cycles:k",
887 .check = test__group2,
888 },
889 [30] = {
890 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
891 .check = test__group3,
892 },
893 [31] = {
894 .name = "{cycles:u,instructions:kp}:p",
895 .check = test__group4,
896 },
897 [32] = {
898 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
899 .check = test__group5,
900 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200901};
902
Jiri Olsaf50246e2012-05-21 09:12:49 +0200903static struct test__event_st test__events_pmu[] = {
904 [0] = {
905 .name = "cpu/config=10,config1,config2=3,period=1000/u",
906 .check = test__checkevent_pmu,
907 },
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200908 [1] = {
909 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
910 .check = test__checkevent_pmu_name,
911 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200912};
913
Jiri Olsa44293922012-06-15 14:31:42 +0800914struct test__term {
915 const char *str;
916 __u32 type;
917 int (*check)(struct list_head *terms);
918};
919
920static struct test__term test__terms[] = {
921 [0] = {
922 .str = "config=10,config1,config2=3,umask=1",
923 .check = test__checkterms_simple,
924 },
925};
926
Jiri Olsa44293922012-06-15 14:31:42 +0800927static int test_event(struct test__event_st *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +0200928{
929 struct perf_evlist *evlist;
930 int ret;
931
932 evlist = perf_evlist__new(NULL, NULL);
933 if (evlist == NULL)
934 return -ENOMEM;
935
936 ret = parse_events(evlist, e->name, 0);
937 if (ret) {
938 pr_debug("failed to parse event '%s', err %d\n",
939 e->name, ret);
940 return ret;
941 }
942
943 ret = e->check(evlist);
944 perf_evlist__delete(evlist);
945
946 return ret;
947}
948
949static int test_events(struct test__event_st *events, unsigned cnt)
950{
951 int ret = 0;
952 unsigned i;
953
954 for (i = 0; i < cnt; i++) {
955 struct test__event_st *e = &events[i];
956
957 pr_debug("running test %d '%s'\n", i, e->name);
Jiri Olsa44293922012-06-15 14:31:42 +0800958 ret = test_event(e);
959 if (ret)
960 break;
961 }
962
963 return ret;
964}
965
966static int test_term(struct test__term *t)
967{
968 struct list_head *terms;
969 int ret;
970
971 terms = malloc(sizeof(*terms));
972 if (!terms)
973 return -ENOMEM;
974
975 INIT_LIST_HEAD(terms);
976
977 ret = parse_events_terms(terms, t->str);
978 if (ret) {
979 pr_debug("failed to parse terms '%s', err %d\n",
980 t->str , ret);
981 return ret;
982 }
983
984 ret = t->check(terms);
985 parse_events__free_terms(terms);
986
987 return ret;
988}
989
990static int test_terms(struct test__term *terms, unsigned cnt)
991{
992 int ret = 0;
993 unsigned i;
994
995 for (i = 0; i < cnt; i++) {
996 struct test__term *t = &terms[i];
997
998 pr_debug("running test %d '%s'\n", i, t->str);
999 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001000 if (ret)
1001 break;
1002 }
1003
1004 return ret;
1005}
1006
1007static int test_pmu(void)
1008{
1009 struct stat st;
1010 char path[PATH_MAX];
1011 int ret;
1012
1013 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1014 sysfs_find_mountpoint());
1015
1016 ret = stat(path, &st);
1017 if (ret)
1018 pr_debug("ommiting PMU cpu tests\n");
1019 return !ret;
1020}
1021
1022int parse_events__test(void)
1023{
1024 int ret;
1025
Jiri Olsaebf124f2012-07-04 00:00:47 +02001026#define TEST_EVENTS(tests) \
1027do { \
1028 ret = test_events(tests, ARRAY_SIZE(tests)); \
1029 if (ret) \
1030 return ret; \
1031} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001032
Jiri Olsaebf124f2012-07-04 00:00:47 +02001033 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001034
Jiri Olsaebf124f2012-07-04 00:00:47 +02001035 if (test_pmu())
1036 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001037
Jiri Olsaebf124f2012-07-04 00:00:47 +02001038 return test_terms(test__terms, ARRAY_SIZE(test__terms));
Jiri Olsaf50246e2012-05-21 09:12:49 +02001039}