blob: e7eb708da32c795123c1f15b2632c33d604a4df4 [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);
26 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
27 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020028 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020029 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
30 return 0;
31}
32
33static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
34{
35 struct perf_evsel *evsel;
36
37 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
38
39 list_for_each_entry(evsel, &evlist->entries, node) {
40 TEST_ASSERT_VAL("wrong type",
41 PERF_TYPE_TRACEPOINT == evsel->attr.type);
42 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020043 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020044 TEST_ASSERT_VAL("wrong sample_period",
45 1 == evsel->attr.sample_period);
46 }
47 return 0;
48}
49
50static int test__checkevent_raw(struct perf_evlist *evlist)
51{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030052 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020053
54 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
55 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
56 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
57 return 0;
58}
59
60static int test__checkevent_numeric(struct perf_evlist *evlist)
61{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030062 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020063
64 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
65 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
66 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
67 return 0;
68}
69
70static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
71{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030072 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020073
74 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
75 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
76 TEST_ASSERT_VAL("wrong config",
77 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
78 return 0;
79}
80
81static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
82{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030083 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020084
85 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
86 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
87 TEST_ASSERT_VAL("wrong config",
88 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
89 TEST_ASSERT_VAL("wrong period",
90 100000 == evsel->attr.sample_period);
91 TEST_ASSERT_VAL("wrong config1",
92 0 == evsel->attr.config1);
93 TEST_ASSERT_VAL("wrong config2",
94 1 == evsel->attr.config2);
95 return 0;
96}
97
98static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
99{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300100 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200101
102 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
103 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
104 TEST_ASSERT_VAL("wrong config",
105 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
106 return 0;
107}
108
109static int test__checkevent_genhw(struct perf_evlist *evlist)
110{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300111 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200112
113 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
115 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
116 return 0;
117}
118
119static int test__checkevent_breakpoint(struct perf_evlist *evlist)
120{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300121 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200122
123 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
124 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
125 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
126 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
127 evsel->attr.bp_type);
128 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
129 evsel->attr.bp_len);
130 return 0;
131}
132
133static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
134{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300135 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200136
137 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
138 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
139 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
140 TEST_ASSERT_VAL("wrong bp_type",
141 HW_BREAKPOINT_X == evsel->attr.bp_type);
142 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
143 return 0;
144}
145
146static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
147{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300148 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200149
150 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
151 TEST_ASSERT_VAL("wrong type",
152 PERF_TYPE_BREAKPOINT == evsel->attr.type);
153 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
154 TEST_ASSERT_VAL("wrong bp_type",
155 HW_BREAKPOINT_R == evsel->attr.bp_type);
156 TEST_ASSERT_VAL("wrong bp_len",
157 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
158 return 0;
159}
160
161static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
162{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300163 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200164
165 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
166 TEST_ASSERT_VAL("wrong type",
167 PERF_TYPE_BREAKPOINT == evsel->attr.type);
168 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
169 TEST_ASSERT_VAL("wrong bp_type",
170 HW_BREAKPOINT_W == evsel->attr.bp_type);
171 TEST_ASSERT_VAL("wrong bp_len",
172 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
173 return 0;
174}
175
Jiri Olsa75827322012-06-29 09:22:54 +0200176static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
177{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300178 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200179
180 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
181 TEST_ASSERT_VAL("wrong type",
182 PERF_TYPE_BREAKPOINT == evsel->attr.type);
183 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
184 TEST_ASSERT_VAL("wrong bp_type",
185 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
186 TEST_ASSERT_VAL("wrong bp_len",
187 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
188 return 0;
189}
190
Jiri Olsaf50246e2012-05-21 09:12:49 +0200191static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
192{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300193 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200194
195 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
196 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
197 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
198 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
199
200 return test__checkevent_tracepoint(evlist);
201}
202
203static int
204test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
205{
206 struct perf_evsel *evsel;
207
208 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
209
210 list_for_each_entry(evsel, &evlist->entries, node) {
211 TEST_ASSERT_VAL("wrong exclude_user",
212 !evsel->attr.exclude_user);
213 TEST_ASSERT_VAL("wrong exclude_kernel",
214 evsel->attr.exclude_kernel);
215 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
216 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
217 }
218
219 return test__checkevent_tracepoint_multi(evlist);
220}
221
222static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
223{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300224 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200225
226 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
227 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
228 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
229 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
230
231 return test__checkevent_raw(evlist);
232}
233
234static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
235{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300236 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200237
238 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
239 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
240 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
241 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
242
243 return test__checkevent_numeric(evlist);
244}
245
246static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
247{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300248 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200249
250 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
251 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
252 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
253 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
254
255 return test__checkevent_symbolic_name(evlist);
256}
257
258static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
259{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300260 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200261
262 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
263 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
264
265 return test__checkevent_symbolic_name(evlist);
266}
267
268static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
269{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300270 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200271
272 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
273 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
274
275 return test__checkevent_symbolic_name(evlist);
276}
277
278static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
279{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300280 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200281
282 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
283 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
284 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
285 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
286
287 return test__checkevent_symbolic_alias(evlist);
288}
289
290static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
291{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300292 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200293
294 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
295 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
296 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
297 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
298
299 return test__checkevent_genhw(evlist);
300}
301
302static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
303{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300304 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200305
Jiri Olsaf50246e2012-05-21 09:12:49 +0200306
307 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
308 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
309 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
310 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200311 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200312 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200313
314 return test__checkevent_breakpoint(evlist);
315}
316
317static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
318{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300319 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200320
321 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
322 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
323 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
324 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200325 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200326 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200327
328 return test__checkevent_breakpoint_x(evlist);
329}
330
331static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
332{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300333 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200334
335 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
336 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
337 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
338 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200339 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200340 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200341
342 return test__checkevent_breakpoint_r(evlist);
343}
344
345static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
346{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300347 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200348
349 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
350 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
351 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
352 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200353 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200354 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200355
356 return test__checkevent_breakpoint_w(evlist);
357}
358
Jiri Olsa75827322012-06-29 09:22:54 +0200359static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
360{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300361 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200362
363 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
364 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
365 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
366 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200367 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200368 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200369
370 return test__checkevent_breakpoint_rw(evlist);
371}
372
Jiri Olsaf50246e2012-05-21 09:12:49 +0200373static int test__checkevent_pmu(struct perf_evlist *evlist)
374{
375
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300376 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200377
378 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
379 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
380 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
381 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
382 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
383 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
384
385 return 0;
386}
387
388static int test__checkevent_list(struct perf_evlist *evlist)
389{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300390 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200391
392 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
393
394 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200395 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
396 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
397 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
398 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
399 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
400 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
401 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
402 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
403
404 /* syscalls:sys_enter_open:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300405 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200406 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
407 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200408 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200409 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
410 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
411 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
412 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
413 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
414
415 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300416 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200417 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
418 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
419 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
420 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
421 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
422 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
423
424 return 0;
425}
426
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200427static int test__checkevent_pmu_name(struct perf_evlist *evlist)
428{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300429 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200430
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200431 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200432 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
433 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
434 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300435 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200436
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200437 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300438 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200439 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
440 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
441 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200442 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200443 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200444
445 return 0;
446}
447
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200448static int test__checkevent_pmu_events(struct perf_evlist *evlist)
449{
450 struct perf_evsel *evsel;
451
452 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
453 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
454 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
455 TEST_ASSERT_VAL("wrong exclude_user",
456 !evsel->attr.exclude_user);
457 TEST_ASSERT_VAL("wrong exclude_kernel",
458 evsel->attr.exclude_kernel);
459 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
460 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
461
462 return 0;
463}
464
Jiri Olsa44293922012-06-15 14:31:42 +0800465static int test__checkterms_simple(struct list_head *terms)
466{
467 struct parse_events__term *term;
468
469 /* config=10 */
470 term = list_entry(terms->next, struct parse_events__term, list);
471 TEST_ASSERT_VAL("wrong type term",
472 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
473 TEST_ASSERT_VAL("wrong type val",
474 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
475 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
476 TEST_ASSERT_VAL("wrong config", !term->config);
477
478 /* config1 */
479 term = list_entry(term->list.next, struct parse_events__term, list);
480 TEST_ASSERT_VAL("wrong type term",
481 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
482 TEST_ASSERT_VAL("wrong type val",
483 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
484 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
485 TEST_ASSERT_VAL("wrong config", !term->config);
486
487 /* config2=3 */
488 term = list_entry(term->list.next, struct parse_events__term, list);
489 TEST_ASSERT_VAL("wrong type term",
490 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
491 TEST_ASSERT_VAL("wrong type val",
492 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
493 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
494 TEST_ASSERT_VAL("wrong config", !term->config);
495
496 /* umask=1*/
497 term = list_entry(term->list.next, struct parse_events__term, list);
498 TEST_ASSERT_VAL("wrong type term",
499 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
500 TEST_ASSERT_VAL("wrong type val",
501 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
502 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
503 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
504
505 return 0;
506}
507
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200508static int test__group1(struct perf_evlist *evlist)
509{
510 struct perf_evsel *evsel, *leader;
511
512 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
513
514 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300515 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200516 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
517 TEST_ASSERT_VAL("wrong config",
518 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
519 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
520 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
521 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
522 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
523 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
524 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900525 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200526
527 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300528 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200529 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
530 TEST_ASSERT_VAL("wrong config",
531 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
532 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
533 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
534 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200535 /* use of precise requires exclude_guest */
536 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200537 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
538 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
539 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
540
541 return 0;
542}
543
544static int test__group2(struct perf_evlist *evlist)
545{
546 struct perf_evsel *evsel, *leader;
547
548 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
549
550 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300551 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200552 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
553 TEST_ASSERT_VAL("wrong config",
554 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
555 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
556 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
557 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
558 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
559 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
560 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900561 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200562
563 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300564 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200565 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
566 TEST_ASSERT_VAL("wrong config",
567 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
568 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
569 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
570 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
571 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
572 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
573 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
574 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
575
576 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300577 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200578 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
579 TEST_ASSERT_VAL("wrong config",
580 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
581 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
582 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
583 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
584 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
585 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
586 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900587 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200588
589 return 0;
590}
591
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300592static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200593{
594 struct perf_evsel *evsel, *leader;
595
596 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
597
598 /* group1 syscalls:sys_enter_open:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300599 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200600 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
601 TEST_ASSERT_VAL("wrong sample_type",
602 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
603 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
604 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
605 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
606 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
607 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
608 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
609 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900610 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200611 TEST_ASSERT_VAL("wrong group name",
612 !strcmp(leader->group_name, "group1"));
613
614 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300615 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200616 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
617 TEST_ASSERT_VAL("wrong config",
618 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
619 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
620 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
621 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200622 /* use of precise requires exclude_guest */
623 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200624 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
625 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
626 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
627 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
628
629 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300630 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200631 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
632 TEST_ASSERT_VAL("wrong config",
633 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
634 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
635 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
636 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
637 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
638 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
639 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900640 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200641 TEST_ASSERT_VAL("wrong group name",
642 !strcmp(leader->group_name, "group2"));
643
644 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300645 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200646 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
647 TEST_ASSERT_VAL("wrong config", 3 == 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);
654 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
655
656 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300657 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
659 TEST_ASSERT_VAL("wrong config",
660 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
661 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
662 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
663 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
664 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
665 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
666 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900667 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200668
669 return 0;
670}
671
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300672static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200673{
674 struct perf_evsel *evsel, *leader;
675
676 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
677
678 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300679 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200680 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
681 TEST_ASSERT_VAL("wrong config",
682 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
683 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
684 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
685 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200686 /* use of precise requires exclude_guest */
687 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200688 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
689 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
690 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900691 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200692
693 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300694 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200695 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
696 TEST_ASSERT_VAL("wrong config",
697 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
698 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
699 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
700 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200701 /* use of precise requires exclude_guest */
702 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200703 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
704 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
705 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
706
707 return 0;
708}
709
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300710static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200711{
712 struct perf_evsel *evsel, *leader;
713
714 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
715
716 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300717 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200718 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
719 TEST_ASSERT_VAL("wrong config",
720 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
721 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
722 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
723 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
724 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
725 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
726 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
727 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900728 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200729
730 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300731 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200732 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
733 TEST_ASSERT_VAL("wrong config",
734 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
735 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
736 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
737 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
738 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
739 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
740 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
741 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
742
743 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300744 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200745 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
746 TEST_ASSERT_VAL("wrong config",
747 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
748 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
749 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
750 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
751 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
752 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
753 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
754 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900755 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200756
757 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300758 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200759 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
760 TEST_ASSERT_VAL("wrong config",
761 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
762 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
763 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
764 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
765 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
766 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
767 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
768 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
769
770 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300771 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200772 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
773 TEST_ASSERT_VAL("wrong config",
774 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
775 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
776 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
777 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
778 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
779 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
780 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900781 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200782
783 return 0;
784}
785
Jiri Olsa82ce75d2012-12-17 14:08:38 +0100786static int count_tracepoints(void)
787{
788 char events_path[PATH_MAX];
789 struct dirent *events_ent;
790 DIR *events_dir;
791 int cnt = 0;
792
793 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
794 debugfs_find_mountpoint());
795
796 events_dir = opendir(events_path);
797
798 TEST_ASSERT_VAL("Can't open events dir", events_dir);
799
800 while ((events_ent = readdir(events_dir))) {
801 char sys_path[PATH_MAX];
802 struct dirent *sys_ent;
803 DIR *sys_dir;
804
805 if (!strcmp(events_ent->d_name, ".")
806 || !strcmp(events_ent->d_name, "..")
807 || !strcmp(events_ent->d_name, "enable")
808 || !strcmp(events_ent->d_name, "header_event")
809 || !strcmp(events_ent->d_name, "header_page"))
810 continue;
811
812 scnprintf(sys_path, PATH_MAX, "%s/%s",
813 events_path, events_ent->d_name);
814
815 sys_dir = opendir(sys_path);
816 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
817
818 while ((sys_ent = readdir(sys_dir))) {
819 if (!strcmp(sys_ent->d_name, ".")
820 || !strcmp(sys_ent->d_name, "..")
821 || !strcmp(sys_ent->d_name, "enable")
822 || !strcmp(sys_ent->d_name, "filter"))
823 continue;
824
825 cnt++;
826 }
827
828 closedir(sys_dir);
829 }
830
831 closedir(events_dir);
832 return cnt;
833}
834
835static int test__all_tracepoints(struct perf_evlist *evlist)
836{
837 TEST_ASSERT_VAL("wrong events count",
838 count_tracepoints() == evlist->nr_entries);
839
840 return test__checkevent_tracepoint_multi(evlist);
841}
842
Jiri Olsaf50246e2012-05-21 09:12:49 +0200843struct test__event_st {
844 const char *name;
845 __u32 type;
846 int (*check)(struct perf_evlist *evlist);
847};
848
849static struct test__event_st test__events[] = {
850 [0] = {
851 .name = "syscalls:sys_enter_open",
852 .check = test__checkevent_tracepoint,
853 },
854 [1] = {
855 .name = "syscalls:*",
856 .check = test__checkevent_tracepoint_multi,
857 },
858 [2] = {
859 .name = "r1a",
860 .check = test__checkevent_raw,
861 },
862 [3] = {
863 .name = "1:1",
864 .check = test__checkevent_numeric,
865 },
866 [4] = {
867 .name = "instructions",
868 .check = test__checkevent_symbolic_name,
869 },
870 [5] = {
871 .name = "cycles/period=100000,config2/",
872 .check = test__checkevent_symbolic_name_config,
873 },
874 [6] = {
875 .name = "faults",
876 .check = test__checkevent_symbolic_alias,
877 },
878 [7] = {
879 .name = "L1-dcache-load-miss",
880 .check = test__checkevent_genhw,
881 },
882 [8] = {
883 .name = "mem:0",
884 .check = test__checkevent_breakpoint,
885 },
886 [9] = {
887 .name = "mem:0:x",
888 .check = test__checkevent_breakpoint_x,
889 },
890 [10] = {
891 .name = "mem:0:r",
892 .check = test__checkevent_breakpoint_r,
893 },
894 [11] = {
895 .name = "mem:0:w",
896 .check = test__checkevent_breakpoint_w,
897 },
898 [12] = {
899 .name = "syscalls:sys_enter_open:k",
900 .check = test__checkevent_tracepoint_modifier,
901 },
902 [13] = {
903 .name = "syscalls:*:u",
904 .check = test__checkevent_tracepoint_multi_modifier,
905 },
906 [14] = {
907 .name = "r1a:kp",
908 .check = test__checkevent_raw_modifier,
909 },
910 [15] = {
911 .name = "1:1:hp",
912 .check = test__checkevent_numeric_modifier,
913 },
914 [16] = {
915 .name = "instructions:h",
916 .check = test__checkevent_symbolic_name_modifier,
917 },
918 [17] = {
919 .name = "faults:u",
920 .check = test__checkevent_symbolic_alias_modifier,
921 },
922 [18] = {
923 .name = "L1-dcache-load-miss:kp",
924 .check = test__checkevent_genhw_modifier,
925 },
926 [19] = {
927 .name = "mem:0:u",
928 .check = test__checkevent_breakpoint_modifier,
929 },
930 [20] = {
931 .name = "mem:0:x:k",
932 .check = test__checkevent_breakpoint_x_modifier,
933 },
934 [21] = {
935 .name = "mem:0:r:hp",
936 .check = test__checkevent_breakpoint_r_modifier,
937 },
938 [22] = {
939 .name = "mem:0:w:up",
940 .check = test__checkevent_breakpoint_w_modifier,
941 },
942 [23] = {
943 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
944 .check = test__checkevent_list,
945 },
946 [24] = {
947 .name = "instructions:G",
948 .check = test__checkevent_exclude_host_modifier,
949 },
950 [25] = {
951 .name = "instructions:H",
952 .check = test__checkevent_exclude_guest_modifier,
953 },
Jiri Olsa75827322012-06-29 09:22:54 +0200954 [26] = {
955 .name = "mem:0:rw",
956 .check = test__checkevent_breakpoint_rw,
957 },
958 [27] = {
959 .name = "mem:0:rw:kp",
960 .check = test__checkevent_breakpoint_rw_modifier,
961 },
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200962 [28] = {
963 .name = "{instructions:k,cycles:upp}",
964 .check = test__group1,
965 },
966 [29] = {
967 .name = "{faults:k,cache-references}:u,cycles:k",
968 .check = test__group2,
969 },
970 [30] = {
971 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
972 .check = test__group3,
973 },
974 [31] = {
975 .name = "{cycles:u,instructions:kp}:p",
976 .check = test__group4,
977 },
978 [32] = {
979 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
980 .check = test__group5,
981 },
Jiri Olsa82ce75d2012-12-17 14:08:38 +0100982 [33] = {
983 .name = "*:*",
984 .check = test__all_tracepoints,
985 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200986};
987
Jiri Olsaf50246e2012-05-21 09:12:49 +0200988static struct test__event_st test__events_pmu[] = {
989 [0] = {
990 .name = "cpu/config=10,config1,config2=3,period=1000/u",
991 .check = test__checkevent_pmu,
992 },
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200993 [1] = {
994 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
995 .check = test__checkevent_pmu_name,
996 },
Jiri Olsaf50246e2012-05-21 09:12:49 +0200997};
998
Jiri Olsa44293922012-06-15 14:31:42 +0800999struct test__term {
1000 const char *str;
1001 __u32 type;
1002 int (*check)(struct list_head *terms);
1003};
1004
1005static struct test__term test__terms[] = {
1006 [0] = {
1007 .str = "config=10,config1,config2=3,umask=1",
1008 .check = test__checkterms_simple,
1009 },
1010};
1011
Jiri Olsa44293922012-06-15 14:31:42 +08001012static int test_event(struct test__event_st *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001013{
1014 struct perf_evlist *evlist;
1015 int ret;
1016
1017 evlist = perf_evlist__new(NULL, NULL);
1018 if (evlist == NULL)
1019 return -ENOMEM;
1020
1021 ret = parse_events(evlist, e->name, 0);
1022 if (ret) {
1023 pr_debug("failed to parse event '%s', err %d\n",
1024 e->name, ret);
1025 return ret;
1026 }
1027
1028 ret = e->check(evlist);
1029 perf_evlist__delete(evlist);
1030
1031 return ret;
1032}
1033
1034static int test_events(struct test__event_st *events, unsigned cnt)
1035{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001036 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001037 unsigned i;
1038
1039 for (i = 0; i < cnt; i++) {
1040 struct test__event_st *e = &events[i];
1041
1042 pr_debug("running test %d '%s'\n", i, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001043 ret1 = test_event(e);
1044 if (ret1)
1045 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001046 }
1047
Robert Richter9bfbbc62012-08-21 20:03:15 +02001048 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001049}
1050
1051static int test_term(struct test__term *t)
1052{
1053 struct list_head *terms;
1054 int ret;
1055
1056 terms = malloc(sizeof(*terms));
1057 if (!terms)
1058 return -ENOMEM;
1059
1060 INIT_LIST_HEAD(terms);
1061
1062 ret = parse_events_terms(terms, t->str);
1063 if (ret) {
1064 pr_debug("failed to parse terms '%s', err %d\n",
1065 t->str , ret);
1066 return ret;
1067 }
1068
1069 ret = t->check(terms);
1070 parse_events__free_terms(terms);
1071
1072 return ret;
1073}
1074
1075static int test_terms(struct test__term *terms, unsigned cnt)
1076{
1077 int ret = 0;
1078 unsigned i;
1079
1080 for (i = 0; i < cnt; i++) {
1081 struct test__term *t = &terms[i];
1082
1083 pr_debug("running test %d '%s'\n", i, t->str);
1084 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001085 if (ret)
1086 break;
1087 }
1088
1089 return ret;
1090}
1091
1092static int test_pmu(void)
1093{
1094 struct stat st;
1095 char path[PATH_MAX];
1096 int ret;
1097
1098 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1099 sysfs_find_mountpoint());
1100
1101 ret = stat(path, &st);
1102 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001103 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001104 return !ret;
1105}
1106
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001107static int test_pmu_events(void)
1108{
1109 struct stat st;
1110 char path[PATH_MAX];
1111 struct dirent *ent;
1112 DIR *dir;
1113 int ret;
1114
1115 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1116 sysfs_find_mountpoint());
1117
1118 ret = stat(path, &st);
1119 if (ret) {
1120 pr_debug("ommiting PMU cpu events tests\n");
1121 return 0;
1122 }
1123
1124 dir = opendir(path);
1125 if (!dir) {
1126 pr_debug("can't open pmu event dir");
1127 return -1;
1128 }
1129
1130 while (!ret && (ent = readdir(dir))) {
1131#define MAX_NAME 100
1132 struct test__event_st e;
1133 char name[MAX_NAME];
1134
1135 if (!strcmp(ent->d_name, ".") ||
1136 !strcmp(ent->d_name, ".."))
1137 continue;
1138
1139 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1140
1141 e.name = name;
1142 e.check = test__checkevent_pmu_events;
1143
1144 ret = test_event(&e);
1145#undef MAX_NAME
1146 }
1147
1148 closedir(dir);
1149 return ret;
1150}
1151
Jiri Olsac81251e2012-11-10 01:46:51 +01001152int test__parse_events(void)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001153{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001154 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001155
Jiri Olsaebf124f2012-07-04 00:00:47 +02001156#define TEST_EVENTS(tests) \
1157do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001158 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1159 if (!ret2) \
1160 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001161} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001162
Jiri Olsaebf124f2012-07-04 00:00:47 +02001163 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001164
Jiri Olsaebf124f2012-07-04 00:00:47 +02001165 if (test_pmu())
1166 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001167
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001168 if (test_pmu()) {
1169 int ret = test_pmu_events();
1170 if (ret)
1171 return ret;
1172 }
1173
Robert Richter9bfbbc62012-08-21 20:03:15 +02001174 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1175 if (!ret2)
1176 ret2 = ret1;
1177
1178 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001179}