blob: 80a8daf54a63a53f671ca3d5ecb758ca661eb42f [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"
Jiri Olsa82ce75d2012-12-17 14:08:38 +01006#include "debugfs.h"
Jiri Olsac81251e2012-11-10 01:46:51 +01007#include "tests.h"
David Howellsd2709c72012-11-19 22:21:03 +00008#include <linux/hw_breakpoint.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +02009
10#define TEST_ASSERT_VAL(text, cond) \
11do { \
12 if (!(cond)) { \
13 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
14 return -1; \
15 } \
16} while (0)
17
Jiri Olsa30f31c02012-08-01 14:48:58 +020018#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
19 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
20
Jiri Olsaf50246e2012-05-21 09:12:49 +020021static int test__checkevent_tracepoint(struct perf_evlist *evlist)
22{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030023 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020024
25 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090026 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020027 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
28 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020029 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020030 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
31 return 0;
32}
33
34static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
35{
36 struct perf_evsel *evsel;
37
38 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090039 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020040
41 list_for_each_entry(evsel, &evlist->entries, node) {
42 TEST_ASSERT_VAL("wrong type",
43 PERF_TYPE_TRACEPOINT == evsel->attr.type);
44 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020045 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020046 TEST_ASSERT_VAL("wrong sample_period",
47 1 == evsel->attr.sample_period);
48 }
49 return 0;
50}
51
52static int test__checkevent_raw(struct perf_evlist *evlist)
53{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030054 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020055
56 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
57 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
58 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
59 return 0;
60}
61
62static int test__checkevent_numeric(struct perf_evlist *evlist)
63{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030064 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020065
66 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
67 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
68 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
69 return 0;
70}
71
72static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
73{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030074 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020075
76 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
77 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
78 TEST_ASSERT_VAL("wrong config",
79 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
80 return 0;
81}
82
83static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
84{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030085 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020086
87 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
88 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
89 TEST_ASSERT_VAL("wrong config",
90 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
91 TEST_ASSERT_VAL("wrong period",
92 100000 == evsel->attr.sample_period);
93 TEST_ASSERT_VAL("wrong config1",
94 0 == evsel->attr.config1);
95 TEST_ASSERT_VAL("wrong config2",
96 1 == evsel->attr.config2);
97 return 0;
98}
99
100static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
101{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300102 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200103
104 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
105 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
106 TEST_ASSERT_VAL("wrong config",
107 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
108 return 0;
109}
110
111static int test__checkevent_genhw(struct perf_evlist *evlist)
112{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300113 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200114
115 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
116 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
117 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
118 return 0;
119}
120
121static int test__checkevent_breakpoint(struct perf_evlist *evlist)
122{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300123 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200124
125 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
126 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
127 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
128 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
129 evsel->attr.bp_type);
130 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
131 evsel->attr.bp_len);
132 return 0;
133}
134
135static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
136{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300137 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200138
139 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
140 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
141 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
142 TEST_ASSERT_VAL("wrong bp_type",
143 HW_BREAKPOINT_X == evsel->attr.bp_type);
144 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
145 return 0;
146}
147
148static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
149{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300150 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200151
152 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
153 TEST_ASSERT_VAL("wrong type",
154 PERF_TYPE_BREAKPOINT == evsel->attr.type);
155 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
156 TEST_ASSERT_VAL("wrong bp_type",
157 HW_BREAKPOINT_R == evsel->attr.bp_type);
158 TEST_ASSERT_VAL("wrong bp_len",
159 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
160 return 0;
161}
162
163static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
164{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300165 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200166
167 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
168 TEST_ASSERT_VAL("wrong type",
169 PERF_TYPE_BREAKPOINT == evsel->attr.type);
170 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
171 TEST_ASSERT_VAL("wrong bp_type",
172 HW_BREAKPOINT_W == evsel->attr.bp_type);
173 TEST_ASSERT_VAL("wrong bp_len",
174 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
175 return 0;
176}
177
Jiri Olsa75827322012-06-29 09:22:54 +0200178static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
179{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300180 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200181
182 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
183 TEST_ASSERT_VAL("wrong type",
184 PERF_TYPE_BREAKPOINT == evsel->attr.type);
185 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
186 TEST_ASSERT_VAL("wrong bp_type",
187 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
188 TEST_ASSERT_VAL("wrong bp_len",
189 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
190 return 0;
191}
192
Jiri Olsaf50246e2012-05-21 09:12:49 +0200193static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
194{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300195 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200196
197 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
198 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
199 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
200 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
201
202 return test__checkevent_tracepoint(evlist);
203}
204
205static int
206test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
207{
208 struct perf_evsel *evsel;
209
210 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
211
212 list_for_each_entry(evsel, &evlist->entries, node) {
213 TEST_ASSERT_VAL("wrong exclude_user",
214 !evsel->attr.exclude_user);
215 TEST_ASSERT_VAL("wrong exclude_kernel",
216 evsel->attr.exclude_kernel);
217 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
218 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
219 }
220
221 return test__checkevent_tracepoint_multi(evlist);
222}
223
224static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
225{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300226 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200227
228 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
229 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
230 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
231 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
232
233 return test__checkevent_raw(evlist);
234}
235
236static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
237{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300238 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200239
240 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
241 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
242 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
243 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
244
245 return test__checkevent_numeric(evlist);
246}
247
248static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
249{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300250 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200251
252 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
253 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
254 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
255 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
256
257 return test__checkevent_symbolic_name(evlist);
258}
259
260static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
261{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300262 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200263
264 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
265 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
266
267 return test__checkevent_symbolic_name(evlist);
268}
269
270static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
271{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300272 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200273
274 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
275 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
276
277 return test__checkevent_symbolic_name(evlist);
278}
279
280static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
281{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300282 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200283
284 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
285 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
286 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
287 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
288
289 return test__checkevent_symbolic_alias(evlist);
290}
291
292static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
293{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300294 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200295
296 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
297 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
298 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
299 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
300
301 return test__checkevent_genhw(evlist);
302}
303
304static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
305{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300306 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200307
Jiri Olsaf50246e2012-05-21 09:12:49 +0200308
309 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
310 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
311 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
312 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200313 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200314 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200315
316 return test__checkevent_breakpoint(evlist);
317}
318
319static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
320{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300321 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200322
323 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
324 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
325 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
326 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200327 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200328 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200329
330 return test__checkevent_breakpoint_x(evlist);
331}
332
333static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
334{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300335 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200336
337 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
338 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
339 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
340 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200341 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200342 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200343
344 return test__checkevent_breakpoint_r(evlist);
345}
346
347static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
348{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300349 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200350
351 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
352 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
353 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
354 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200355 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200356 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200357
358 return test__checkevent_breakpoint_w(evlist);
359}
360
Jiri Olsa75827322012-06-29 09:22:54 +0200361static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
362{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300363 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200364
365 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
366 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
367 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
368 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200369 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200370 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200371
372 return test__checkevent_breakpoint_rw(evlist);
373}
374
Jiri Olsaf50246e2012-05-21 09:12:49 +0200375static int test__checkevent_pmu(struct perf_evlist *evlist)
376{
377
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300378 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200379
380 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
381 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
382 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
383 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
384 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
385 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
386
387 return 0;
388}
389
390static int test__checkevent_list(struct perf_evlist *evlist)
391{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300392 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200393
394 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
395
396 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200397 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
398 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
399 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
400 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
401 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
402 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
403 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
404 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
405
406 /* syscalls:sys_enter_open:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300407 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200408 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
409 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200410 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200411 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
412 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
413 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
414 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
415 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
416
417 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300418 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200419 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
420 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
421 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
422 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
423 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
424 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
425
426 return 0;
427}
428
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200429static int test__checkevent_pmu_name(struct perf_evlist *evlist)
430{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300431 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200432
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200433 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200434 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
435 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
436 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300437 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200438
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200439 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300440 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200441 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
442 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
443 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200444 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200445 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200446
447 return 0;
448}
449
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200450static int test__checkevent_pmu_events(struct perf_evlist *evlist)
451{
452 struct perf_evsel *evsel;
453
454 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
455 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
456 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
457 TEST_ASSERT_VAL("wrong exclude_user",
458 !evsel->attr.exclude_user);
459 TEST_ASSERT_VAL("wrong exclude_kernel",
460 evsel->attr.exclude_kernel);
461 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
462 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
463
464 return 0;
465}
466
Jiri Olsa44293922012-06-15 14:31:42 +0800467static int test__checkterms_simple(struct list_head *terms)
468{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300469 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800470
471 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300472 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800473 TEST_ASSERT_VAL("wrong type term",
474 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
475 TEST_ASSERT_VAL("wrong type val",
476 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
477 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
478 TEST_ASSERT_VAL("wrong config", !term->config);
479
480 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300481 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800482 TEST_ASSERT_VAL("wrong type term",
483 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
484 TEST_ASSERT_VAL("wrong type val",
485 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
486 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
487 TEST_ASSERT_VAL("wrong config", !term->config);
488
489 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300490 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800491 TEST_ASSERT_VAL("wrong type term",
492 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
493 TEST_ASSERT_VAL("wrong type val",
494 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
495 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
496 TEST_ASSERT_VAL("wrong config", !term->config);
497
498 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300499 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800500 TEST_ASSERT_VAL("wrong type term",
501 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
502 TEST_ASSERT_VAL("wrong type val",
503 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
504 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
505 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
506
507 return 0;
508}
509
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200510static int test__group1(struct perf_evlist *evlist)
511{
512 struct perf_evsel *evsel, *leader;
513
514 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900515 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200516
517 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300518 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200519 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
520 TEST_ASSERT_VAL("wrong config",
521 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
522 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
523 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
524 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
525 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
526 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
527 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900528 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900529 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
530 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200531
532 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300533 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200534 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
535 TEST_ASSERT_VAL("wrong config",
536 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
537 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
538 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
539 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200540 /* use of precise requires exclude_guest */
541 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200542 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
543 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
544 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900545 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200546
547 return 0;
548}
549
550static int test__group2(struct perf_evlist *evlist)
551{
552 struct perf_evsel *evsel, *leader;
553
554 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900555 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200556
557 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300558 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200559 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
560 TEST_ASSERT_VAL("wrong config",
561 PERF_COUNT_SW_PAGE_FAULTS == 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);
Namhyung Kim823254e2012-11-29 15:38:30 +0900568 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900569 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
570 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200571
572 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300573 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200574 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
575 TEST_ASSERT_VAL("wrong config",
576 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
577 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
578 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
579 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
580 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
581 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
582 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
583 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900584 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200585
586 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300587 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200588 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
589 TEST_ASSERT_VAL("wrong config",
590 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
591 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
592 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
593 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
594 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
595 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
596 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900597 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200598
599 return 0;
600}
601
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300602static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200603{
604 struct perf_evsel *evsel, *leader;
605
606 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900607 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200608
609 /* group1 syscalls:sys_enter_open:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300610 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200611 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
612 TEST_ASSERT_VAL("wrong sample_type",
613 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
614 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
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);
Namhyung Kim823254e2012-11-29 15:38:30 +0900621 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200622 TEST_ASSERT_VAL("wrong group name",
623 !strcmp(leader->group_name, "group1"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900624 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
625 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200626
627 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300628 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200629 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
630 TEST_ASSERT_VAL("wrong config",
631 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
632 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
633 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
634 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200635 /* use of precise requires exclude_guest */
636 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200637 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
638 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
639 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
640 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900641 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200642
643 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300644 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200645 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
646 TEST_ASSERT_VAL("wrong config",
647 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
648 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
649 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
650 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
651 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
652 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
653 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900654 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200655 TEST_ASSERT_VAL("wrong group name",
656 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900657 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
658 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200659
660 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300661 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200662 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
663 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
664 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
665 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
666 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
667 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
668 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
669 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
670 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900671 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200672
673 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300674 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200675 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
676 TEST_ASSERT_VAL("wrong config",
677 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
678 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
679 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
680 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
681 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
682 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
683 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900684 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200685
686 return 0;
687}
688
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300689static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200690{
691 struct perf_evsel *evsel, *leader;
692
693 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900694 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200695
696 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300697 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200698 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
699 TEST_ASSERT_VAL("wrong config",
700 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
701 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
702 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
703 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200704 /* use of precise requires exclude_guest */
705 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200706 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
707 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
708 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900709 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900710 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
711 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200712
713 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300714 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200715 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
716 TEST_ASSERT_VAL("wrong config",
717 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
718 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
719 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
720 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200721 /* use of precise requires exclude_guest */
722 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200723 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
724 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
725 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900726 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200727
728 return 0;
729}
730
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300731static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200732{
733 struct perf_evsel *evsel, *leader;
734
735 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900736 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200737
738 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300739 evsel = leader = perf_evlist__first(evlist);
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_CPU_CYCLES == 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 group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900750 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900751 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
752 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200753
754 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300755 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200756 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
757 TEST_ASSERT_VAL("wrong config",
758 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
759 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
760 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
761 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
762 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
763 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
764 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
765 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900766 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200767
768 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300769 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200770 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
771 TEST_ASSERT_VAL("wrong config",
772 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
773 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
774 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
775 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
776 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
777 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
778 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
779 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900780 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900781 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
782 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200783
784 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300785 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200786 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
787 TEST_ASSERT_VAL("wrong config",
788 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
789 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
790 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
791 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
792 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
793 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
794 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
795 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900796 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200797
798 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300799 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200800 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
801 TEST_ASSERT_VAL("wrong config",
802 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
803 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
804 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
805 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
806 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
807 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
808 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900809 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200810
811 return 0;
812}
813
Jiri Olsa82ce75d2012-12-17 14:08:38 +0100814static int count_tracepoints(void)
815{
816 char events_path[PATH_MAX];
817 struct dirent *events_ent;
818 DIR *events_dir;
819 int cnt = 0;
820
821 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
822 debugfs_find_mountpoint());
823
824 events_dir = opendir(events_path);
825
826 TEST_ASSERT_VAL("Can't open events dir", events_dir);
827
828 while ((events_ent = readdir(events_dir))) {
829 char sys_path[PATH_MAX];
830 struct dirent *sys_ent;
831 DIR *sys_dir;
832
833 if (!strcmp(events_ent->d_name, ".")
834 || !strcmp(events_ent->d_name, "..")
835 || !strcmp(events_ent->d_name, "enable")
836 || !strcmp(events_ent->d_name, "header_event")
837 || !strcmp(events_ent->d_name, "header_page"))
838 continue;
839
840 scnprintf(sys_path, PATH_MAX, "%s/%s",
841 events_path, events_ent->d_name);
842
843 sys_dir = opendir(sys_path);
844 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
845
846 while ((sys_ent = readdir(sys_dir))) {
847 if (!strcmp(sys_ent->d_name, ".")
848 || !strcmp(sys_ent->d_name, "..")
849 || !strcmp(sys_ent->d_name, "enable")
850 || !strcmp(sys_ent->d_name, "filter"))
851 continue;
852
853 cnt++;
854 }
855
856 closedir(sys_dir);
857 }
858
859 closedir(events_dir);
860 return cnt;
861}
862
863static int test__all_tracepoints(struct perf_evlist *evlist)
864{
865 TEST_ASSERT_VAL("wrong events count",
866 count_tracepoints() == evlist->nr_entries);
867
868 return test__checkevent_tracepoint_multi(evlist);
869}
870
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300871struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200872 const char *name;
873 __u32 type;
874 int (*check)(struct perf_evlist *evlist);
875};
876
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300877static struct evlist_test test__events[] = {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200878 [0] = {
879 .name = "syscalls:sys_enter_open",
880 .check = test__checkevent_tracepoint,
881 },
882 [1] = {
883 .name = "syscalls:*",
884 .check = test__checkevent_tracepoint_multi,
885 },
886 [2] = {
887 .name = "r1a",
888 .check = test__checkevent_raw,
889 },
890 [3] = {
891 .name = "1:1",
892 .check = test__checkevent_numeric,
893 },
894 [4] = {
895 .name = "instructions",
896 .check = test__checkevent_symbolic_name,
897 },
898 [5] = {
899 .name = "cycles/period=100000,config2/",
900 .check = test__checkevent_symbolic_name_config,
901 },
902 [6] = {
903 .name = "faults",
904 .check = test__checkevent_symbolic_alias,
905 },
906 [7] = {
907 .name = "L1-dcache-load-miss",
908 .check = test__checkevent_genhw,
909 },
910 [8] = {
911 .name = "mem:0",
912 .check = test__checkevent_breakpoint,
913 },
914 [9] = {
915 .name = "mem:0:x",
916 .check = test__checkevent_breakpoint_x,
917 },
918 [10] = {
919 .name = "mem:0:r",
920 .check = test__checkevent_breakpoint_r,
921 },
922 [11] = {
923 .name = "mem:0:w",
924 .check = test__checkevent_breakpoint_w,
925 },
926 [12] = {
927 .name = "syscalls:sys_enter_open:k",
928 .check = test__checkevent_tracepoint_modifier,
929 },
930 [13] = {
931 .name = "syscalls:*:u",
932 .check = test__checkevent_tracepoint_multi_modifier,
933 },
934 [14] = {
935 .name = "r1a:kp",
936 .check = test__checkevent_raw_modifier,
937 },
938 [15] = {
939 .name = "1:1:hp",
940 .check = test__checkevent_numeric_modifier,
941 },
942 [16] = {
943 .name = "instructions:h",
944 .check = test__checkevent_symbolic_name_modifier,
945 },
946 [17] = {
947 .name = "faults:u",
948 .check = test__checkevent_symbolic_alias_modifier,
949 },
950 [18] = {
951 .name = "L1-dcache-load-miss:kp",
952 .check = test__checkevent_genhw_modifier,
953 },
954 [19] = {
955 .name = "mem:0:u",
956 .check = test__checkevent_breakpoint_modifier,
957 },
958 [20] = {
959 .name = "mem:0:x:k",
960 .check = test__checkevent_breakpoint_x_modifier,
961 },
962 [21] = {
963 .name = "mem:0:r:hp",
964 .check = test__checkevent_breakpoint_r_modifier,
965 },
966 [22] = {
967 .name = "mem:0:w:up",
968 .check = test__checkevent_breakpoint_w_modifier,
969 },
970 [23] = {
971 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
972 .check = test__checkevent_list,
973 },
974 [24] = {
975 .name = "instructions:G",
976 .check = test__checkevent_exclude_host_modifier,
977 },
978 [25] = {
979 .name = "instructions:H",
980 .check = test__checkevent_exclude_guest_modifier,
981 },
Jiri Olsa75827322012-06-29 09:22:54 +0200982 [26] = {
983 .name = "mem:0:rw",
984 .check = test__checkevent_breakpoint_rw,
985 },
986 [27] = {
987 .name = "mem:0:rw:kp",
988 .check = test__checkevent_breakpoint_rw_modifier,
989 },
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200990 [28] = {
991 .name = "{instructions:k,cycles:upp}",
992 .check = test__group1,
993 },
994 [29] = {
995 .name = "{faults:k,cache-references}:u,cycles:k",
996 .check = test__group2,
997 },
998 [30] = {
999 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1000 .check = test__group3,
1001 },
1002 [31] = {
1003 .name = "{cycles:u,instructions:kp}:p",
1004 .check = test__group4,
1005 },
1006 [32] = {
1007 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1008 .check = test__group5,
1009 },
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001010 [33] = {
1011 .name = "*:*",
1012 .check = test__all_tracepoints,
1013 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001014};
1015
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001016static struct evlist_test test__events_pmu[] = {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001017 [0] = {
1018 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1019 .check = test__checkevent_pmu,
1020 },
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001021 [1] = {
1022 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1023 .check = test__checkevent_pmu_name,
1024 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001025};
1026
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001027struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001028 const char *str;
1029 __u32 type;
1030 int (*check)(struct list_head *terms);
1031};
1032
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001033static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001034 [0] = {
1035 .str = "config=10,config1,config2=3,umask=1",
1036 .check = test__checkterms_simple,
1037 },
1038};
1039
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001040static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001041{
1042 struct perf_evlist *evlist;
1043 int ret;
1044
1045 evlist = perf_evlist__new(NULL, NULL);
1046 if (evlist == NULL)
1047 return -ENOMEM;
1048
Jiri Olsad8f7bbc2013-01-15 14:39:51 +01001049 ret = parse_events(evlist, e->name);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001050 if (ret) {
1051 pr_debug("failed to parse event '%s', err %d\n",
1052 e->name, ret);
1053 return ret;
1054 }
1055
1056 ret = e->check(evlist);
1057 perf_evlist__delete(evlist);
1058
1059 return ret;
1060}
1061
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001062static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001063{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001064 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001065 unsigned i;
1066
1067 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001068 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001069
1070 pr_debug("running test %d '%s'\n", i, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001071 ret1 = test_event(e);
1072 if (ret1)
1073 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001074 }
1075
Robert Richter9bfbbc62012-08-21 20:03:15 +02001076 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001077}
1078
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001079static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001080{
1081 struct list_head *terms;
1082 int ret;
1083
1084 terms = malloc(sizeof(*terms));
1085 if (!terms)
1086 return -ENOMEM;
1087
1088 INIT_LIST_HEAD(terms);
1089
1090 ret = parse_events_terms(terms, t->str);
1091 if (ret) {
1092 pr_debug("failed to parse terms '%s', err %d\n",
1093 t->str , ret);
1094 return ret;
1095 }
1096
1097 ret = t->check(terms);
1098 parse_events__free_terms(terms);
1099
1100 return ret;
1101}
1102
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001103static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001104{
1105 int ret = 0;
1106 unsigned i;
1107
1108 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001109 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001110
1111 pr_debug("running test %d '%s'\n", i, t->str);
1112 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001113 if (ret)
1114 break;
1115 }
1116
1117 return ret;
1118}
1119
1120static int test_pmu(void)
1121{
1122 struct stat st;
1123 char path[PATH_MAX];
1124 int ret;
1125
1126 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1127 sysfs_find_mountpoint());
1128
1129 ret = stat(path, &st);
1130 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001131 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001132 return !ret;
1133}
1134
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001135static int test_pmu_events(void)
1136{
1137 struct stat st;
1138 char path[PATH_MAX];
1139 struct dirent *ent;
1140 DIR *dir;
1141 int ret;
1142
1143 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1144 sysfs_find_mountpoint());
1145
1146 ret = stat(path, &st);
1147 if (ret) {
1148 pr_debug("ommiting PMU cpu events tests\n");
1149 return 0;
1150 }
1151
1152 dir = opendir(path);
1153 if (!dir) {
1154 pr_debug("can't open pmu event dir");
1155 return -1;
1156 }
1157
1158 while (!ret && (ent = readdir(dir))) {
1159#define MAX_NAME 100
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001160 struct evlist_test e;
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001161 char name[MAX_NAME];
1162
1163 if (!strcmp(ent->d_name, ".") ||
1164 !strcmp(ent->d_name, ".."))
1165 continue;
1166
1167 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1168
1169 e.name = name;
1170 e.check = test__checkevent_pmu_events;
1171
1172 ret = test_event(&e);
1173#undef MAX_NAME
1174 }
1175
1176 closedir(dir);
1177 return ret;
1178}
1179
Jiri Olsac81251e2012-11-10 01:46:51 +01001180int test__parse_events(void)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001181{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001182 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001183
Jiri Olsaebf124f2012-07-04 00:00:47 +02001184#define TEST_EVENTS(tests) \
1185do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001186 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1187 if (!ret2) \
1188 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001189} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001190
Jiri Olsaebf124f2012-07-04 00:00:47 +02001191 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001192
Jiri Olsaebf124f2012-07-04 00:00:47 +02001193 if (test_pmu())
1194 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001195
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001196 if (test_pmu()) {
1197 int ret = test_pmu_events();
1198 if (ret)
1199 return ret;
1200 }
1201
Robert Richter9bfbbc62012-08-21 20:03:15 +02001202 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1203 if (!ret2)
1204 ret2 = ret1;
1205
1206 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001207}