blob: 6ef213b35ecd0bf4c83729f8c71f05c3631716fd [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"
David Howellsd2709c72012-11-19 22:21:03 +00006#include <linux/hw_breakpoint.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +02007
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
Jiri Olsaf50246e2012-05-21 09:12:49 +0200304
305 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
306 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
307 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
308 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200309 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200310 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200311
312 return test__checkevent_breakpoint(evlist);
313}
314
315static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
316{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300317 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200318
319 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
320 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
321 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
322 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200323 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200324 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200325
326 return test__checkevent_breakpoint_x(evlist);
327}
328
329static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
330{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300331 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200332
333 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
334 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
335 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
336 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200337 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200338 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200339
340 return test__checkevent_breakpoint_r(evlist);
341}
342
343static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
344{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300345 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200346
347 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
348 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
349 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
350 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200351 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200352 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200353
354 return test__checkevent_breakpoint_w(evlist);
355}
356
Jiri Olsa75827322012-06-29 09:22:54 +0200357static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
358{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300359 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200360
361 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
362 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
363 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
364 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200365 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200366 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200367
368 return test__checkevent_breakpoint_rw(evlist);
369}
370
Jiri Olsaf50246e2012-05-21 09:12:49 +0200371static int test__checkevent_pmu(struct perf_evlist *evlist)
372{
373
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300374 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200375
376 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
377 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
378 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
379 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
380 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
381 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
382
383 return 0;
384}
385
386static int test__checkevent_list(struct perf_evlist *evlist)
387{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300388 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200389
390 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
391
392 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200393 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
394 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
395 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
396 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
397 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
398 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
399 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
400 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
401
402 /* syscalls:sys_enter_open:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300403 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200404 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
405 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200406 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200407 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
408 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
409 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
410 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
411 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
412
413 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300414 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200415 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
416 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
417 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
418 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
419 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
420 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
421
422 return 0;
423}
424
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200425static int test__checkevent_pmu_name(struct perf_evlist *evlist)
426{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300427 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200428
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200429 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200430 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
431 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
432 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300433 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200434
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200435 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300436 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200437 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
438 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
439 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200440 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200441 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200442
443 return 0;
444}
445
Jiri Olsa44293922012-06-15 14:31:42 +0800446static int test__checkterms_simple(struct list_head *terms)
447{
448 struct parse_events__term *term;
449
450 /* config=10 */
451 term = list_entry(terms->next, struct parse_events__term, list);
452 TEST_ASSERT_VAL("wrong type term",
453 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
454 TEST_ASSERT_VAL("wrong type val",
455 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
456 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
457 TEST_ASSERT_VAL("wrong config", !term->config);
458
459 /* config1 */
460 term = list_entry(term->list.next, struct parse_events__term, list);
461 TEST_ASSERT_VAL("wrong type term",
462 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
463 TEST_ASSERT_VAL("wrong type val",
464 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
465 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
466 TEST_ASSERT_VAL("wrong config", !term->config);
467
468 /* config2=3 */
469 term = list_entry(term->list.next, struct parse_events__term, list);
470 TEST_ASSERT_VAL("wrong type term",
471 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
472 TEST_ASSERT_VAL("wrong type val",
473 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
474 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
475 TEST_ASSERT_VAL("wrong config", !term->config);
476
477 /* umask=1*/
478 term = list_entry(term->list.next, struct parse_events__term, list);
479 TEST_ASSERT_VAL("wrong type term",
480 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
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 == 1);
484 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
485
486 return 0;
487}
488
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200489static int test__group1(struct perf_evlist *evlist)
490{
491 struct perf_evsel *evsel, *leader;
492
493 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
494
495 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300496 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200497 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
498 TEST_ASSERT_VAL("wrong config",
499 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
500 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
501 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
502 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
503 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
504 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
505 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
506 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
507
508 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300509 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200510 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
511 TEST_ASSERT_VAL("wrong config",
512 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
513 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
514 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
515 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200516 /* use of precise requires exclude_guest */
517 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200518 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
519 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
520 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
521
522 return 0;
523}
524
525static int test__group2(struct perf_evlist *evlist)
526{
527 struct perf_evsel *evsel, *leader;
528
529 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
530
531 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300532 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200533 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
534 TEST_ASSERT_VAL("wrong config",
535 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
536 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
537 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
538 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
539 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
540 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
541 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
542 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
543
544 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300545 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200546 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
547 TEST_ASSERT_VAL("wrong config",
548 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
549 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
550 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
551 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
552 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
553 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
554 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
555 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
556
557 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300558 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200559 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
560 TEST_ASSERT_VAL("wrong config",
561 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
562 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
563 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
564 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
565 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
566 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
567 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
568 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
569
570 return 0;
571}
572
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300573static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200574{
575 struct perf_evsel *evsel, *leader;
576
577 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
578
579 /* group1 syscalls:sys_enter_open:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300580 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200581 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
582 TEST_ASSERT_VAL("wrong sample_type",
583 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
584 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
585 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
586 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
587 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
588 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
589 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
590 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
591 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
592 TEST_ASSERT_VAL("wrong group name",
593 !strcmp(leader->group_name, "group1"));
594
595 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300596 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200597 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
598 TEST_ASSERT_VAL("wrong config",
599 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
600 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
601 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
602 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200603 /* use of precise requires exclude_guest */
604 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200605 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
606 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
607 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
608 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
609
610 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300611 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200612 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
613 TEST_ASSERT_VAL("wrong config",
614 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
615 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
616 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
617 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
618 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
619 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
620 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
621 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
622 TEST_ASSERT_VAL("wrong group name",
623 !strcmp(leader->group_name, "group2"));
624
625 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300626 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200627 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
628 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
629 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
630 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
631 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
632 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
633 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
634 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
635 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
636
637 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300638 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200639 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
640 TEST_ASSERT_VAL("wrong config",
641 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
642 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
643 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
644 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
645 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
646 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
647 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
648 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
649
650 return 0;
651}
652
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300653static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200654{
655 struct perf_evsel *evsel, *leader;
656
657 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
658
659 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300660 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200661 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
662 TEST_ASSERT_VAL("wrong config",
663 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
664 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
665 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
666 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200667 /* use of precise requires exclude_guest */
668 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200669 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
670 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
671 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
672 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
673
674 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300675 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200676 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
677 TEST_ASSERT_VAL("wrong config",
678 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
679 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
680 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
681 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200682 /* use of precise requires exclude_guest */
683 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200684 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
685 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
686 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
687
688 return 0;
689}
690
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300691static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200692{
693 struct perf_evsel *evsel, *leader;
694
695 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
696
697 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300698 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200699 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
700 TEST_ASSERT_VAL("wrong config",
701 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
702 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
703 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
704 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
705 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
706 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
707 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
708 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
709 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
710
711 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300712 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200713 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
714 TEST_ASSERT_VAL("wrong config",
715 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
716 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
717 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
718 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
719 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
720 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
721 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
722 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
723
724 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300725 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200726 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
727 TEST_ASSERT_VAL("wrong config",
728 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
729 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
730 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
731 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
732 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
733 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
734 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
735 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
736 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
737
738 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300739 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200740 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
741 TEST_ASSERT_VAL("wrong config",
742 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
743 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
744 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
745 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
746 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
747 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
748 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
749 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
750
751 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300752 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200753 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
754 TEST_ASSERT_VAL("wrong config",
755 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
756 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
757 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
758 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
759 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
760 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
761 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
762 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
763
764 return 0;
765}
766
Jiri Olsaf50246e2012-05-21 09:12:49 +0200767struct test__event_st {
768 const char *name;
769 __u32 type;
770 int (*check)(struct perf_evlist *evlist);
771};
772
773static struct test__event_st test__events[] = {
774 [0] = {
775 .name = "syscalls:sys_enter_open",
776 .check = test__checkevent_tracepoint,
777 },
778 [1] = {
779 .name = "syscalls:*",
780 .check = test__checkevent_tracepoint_multi,
781 },
782 [2] = {
783 .name = "r1a",
784 .check = test__checkevent_raw,
785 },
786 [3] = {
787 .name = "1:1",
788 .check = test__checkevent_numeric,
789 },
790 [4] = {
791 .name = "instructions",
792 .check = test__checkevent_symbolic_name,
793 },
794 [5] = {
795 .name = "cycles/period=100000,config2/",
796 .check = test__checkevent_symbolic_name_config,
797 },
798 [6] = {
799 .name = "faults",
800 .check = test__checkevent_symbolic_alias,
801 },
802 [7] = {
803 .name = "L1-dcache-load-miss",
804 .check = test__checkevent_genhw,
805 },
806 [8] = {
807 .name = "mem:0",
808 .check = test__checkevent_breakpoint,
809 },
810 [9] = {
811 .name = "mem:0:x",
812 .check = test__checkevent_breakpoint_x,
813 },
814 [10] = {
815 .name = "mem:0:r",
816 .check = test__checkevent_breakpoint_r,
817 },
818 [11] = {
819 .name = "mem:0:w",
820 .check = test__checkevent_breakpoint_w,
821 },
822 [12] = {
823 .name = "syscalls:sys_enter_open:k",
824 .check = test__checkevent_tracepoint_modifier,
825 },
826 [13] = {
827 .name = "syscalls:*:u",
828 .check = test__checkevent_tracepoint_multi_modifier,
829 },
830 [14] = {
831 .name = "r1a:kp",
832 .check = test__checkevent_raw_modifier,
833 },
834 [15] = {
835 .name = "1:1:hp",
836 .check = test__checkevent_numeric_modifier,
837 },
838 [16] = {
839 .name = "instructions:h",
840 .check = test__checkevent_symbolic_name_modifier,
841 },
842 [17] = {
843 .name = "faults:u",
844 .check = test__checkevent_symbolic_alias_modifier,
845 },
846 [18] = {
847 .name = "L1-dcache-load-miss:kp",
848 .check = test__checkevent_genhw_modifier,
849 },
850 [19] = {
851 .name = "mem:0:u",
852 .check = test__checkevent_breakpoint_modifier,
853 },
854 [20] = {
855 .name = "mem:0:x:k",
856 .check = test__checkevent_breakpoint_x_modifier,
857 },
858 [21] = {
859 .name = "mem:0:r:hp",
860 .check = test__checkevent_breakpoint_r_modifier,
861 },
862 [22] = {
863 .name = "mem:0:w:up",
864 .check = test__checkevent_breakpoint_w_modifier,
865 },
866 [23] = {
867 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
868 .check = test__checkevent_list,
869 },
870 [24] = {
871 .name = "instructions:G",
872 .check = test__checkevent_exclude_host_modifier,
873 },
874 [25] = {
875 .name = "instructions:H",
876 .check = test__checkevent_exclude_guest_modifier,
877 },
Jiri Olsa75827322012-06-29 09:22:54 +0200878 [26] = {
879 .name = "mem:0:rw",
880 .check = test__checkevent_breakpoint_rw,
881 },
882 [27] = {
883 .name = "mem:0:rw:kp",
884 .check = test__checkevent_breakpoint_rw_modifier,
885 },
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200886 [28] = {
887 .name = "{instructions:k,cycles:upp}",
888 .check = test__group1,
889 },
890 [29] = {
891 .name = "{faults:k,cache-references}:u,cycles:k",
892 .check = test__group2,
893 },
894 [30] = {
895 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
896 .check = test__group3,
897 },
898 [31] = {
899 .name = "{cycles:u,instructions:kp}:p",
900 .check = test__group4,
901 },
902 [32] = {
903 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
904 .check = test__group5,
905 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200906};
907
Jiri Olsaf50246e2012-05-21 09:12:49 +0200908static struct test__event_st test__events_pmu[] = {
909 [0] = {
910 .name = "cpu/config=10,config1,config2=3,period=1000/u",
911 .check = test__checkevent_pmu,
912 },
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200913 [1] = {
914 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
915 .check = test__checkevent_pmu_name,
916 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200917};
918
Jiri Olsa44293922012-06-15 14:31:42 +0800919struct test__term {
920 const char *str;
921 __u32 type;
922 int (*check)(struct list_head *terms);
923};
924
925static struct test__term test__terms[] = {
926 [0] = {
927 .str = "config=10,config1,config2=3,umask=1",
928 .check = test__checkterms_simple,
929 },
930};
931
Jiri Olsa44293922012-06-15 14:31:42 +0800932static int test_event(struct test__event_st *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +0200933{
934 struct perf_evlist *evlist;
935 int ret;
936
937 evlist = perf_evlist__new(NULL, NULL);
938 if (evlist == NULL)
939 return -ENOMEM;
940
941 ret = parse_events(evlist, e->name, 0);
942 if (ret) {
943 pr_debug("failed to parse event '%s', err %d\n",
944 e->name, ret);
945 return ret;
946 }
947
948 ret = e->check(evlist);
949 perf_evlist__delete(evlist);
950
951 return ret;
952}
953
954static int test_events(struct test__event_st *events, unsigned cnt)
955{
Robert Richter9bfbbc62012-08-21 20:03:15 +0200956 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +0200957 unsigned i;
958
959 for (i = 0; i < cnt; i++) {
960 struct test__event_st *e = &events[i];
961
962 pr_debug("running test %d '%s'\n", i, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +0200963 ret1 = test_event(e);
964 if (ret1)
965 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +0800966 }
967
Robert Richter9bfbbc62012-08-21 20:03:15 +0200968 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +0800969}
970
971static int test_term(struct test__term *t)
972{
973 struct list_head *terms;
974 int ret;
975
976 terms = malloc(sizeof(*terms));
977 if (!terms)
978 return -ENOMEM;
979
980 INIT_LIST_HEAD(terms);
981
982 ret = parse_events_terms(terms, t->str);
983 if (ret) {
984 pr_debug("failed to parse terms '%s', err %d\n",
985 t->str , ret);
986 return ret;
987 }
988
989 ret = t->check(terms);
990 parse_events__free_terms(terms);
991
992 return ret;
993}
994
995static int test_terms(struct test__term *terms, unsigned cnt)
996{
997 int ret = 0;
998 unsigned i;
999
1000 for (i = 0; i < cnt; i++) {
1001 struct test__term *t = &terms[i];
1002
1003 pr_debug("running test %d '%s'\n", i, t->str);
1004 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001005 if (ret)
1006 break;
1007 }
1008
1009 return ret;
1010}
1011
1012static int test_pmu(void)
1013{
1014 struct stat st;
1015 char path[PATH_MAX];
1016 int ret;
1017
1018 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1019 sysfs_find_mountpoint());
1020
1021 ret = stat(path, &st);
1022 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001023 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001024 return !ret;
1025}
1026
1027int parse_events__test(void)
1028{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001029 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001030
Jiri Olsaebf124f2012-07-04 00:00:47 +02001031#define TEST_EVENTS(tests) \
1032do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001033 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1034 if (!ret2) \
1035 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001036} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001037
Jiri Olsaebf124f2012-07-04 00:00:47 +02001038 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001039
Jiri Olsaebf124f2012-07-04 00:00:47 +02001040 if (test_pmu())
1041 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001042
Robert Richter9bfbbc62012-08-21 20:03:15 +02001043 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1044 if (!ret2)
1045 ret2 = ret1;
1046
1047 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001048}