blob: 63986f9db5807a6b14034e7aba0200e37ed3fecb [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);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100580 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200581 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 Olsa5a30a992013-02-04 10:56:43 +0100814static int test__group_gh1(struct perf_evlist *evlist)
815{
816 struct perf_evsel *evsel, *leader;
817
818 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
819 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
820
821 /* cycles + :H group modifier */
822 evsel = leader = perf_evlist__first(evlist);
823 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
824 TEST_ASSERT_VAL("wrong config",
825 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
826 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
827 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
828 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
829 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
830 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
831 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
832 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
833 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
834 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
835 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
836
837 /* cache-misses:G + :H group modifier */
838 evsel = perf_evsel__next(evsel);
839 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
840 TEST_ASSERT_VAL("wrong config",
841 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
842 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
843 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
844 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
845 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
846 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
847 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
848 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
849 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
850
851 return 0;
852}
853
854static int test__group_gh2(struct perf_evlist *evlist)
855{
856 struct perf_evsel *evsel, *leader;
857
858 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
859 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
860
861 /* cycles + :G group modifier */
862 evsel = leader = perf_evlist__first(evlist);
863 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
864 TEST_ASSERT_VAL("wrong config",
865 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
866 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
867 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
868 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
869 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
870 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
871 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
872 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
873 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
874 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
875 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
876
877 /* cache-misses:H + :G group modifier */
878 evsel = perf_evsel__next(evsel);
879 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
880 TEST_ASSERT_VAL("wrong config",
881 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
882 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
883 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
884 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
885 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
886 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
887 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
888 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
889 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
890
891 return 0;
892}
893
894static int test__group_gh3(struct perf_evlist *evlist)
895{
896 struct perf_evsel *evsel, *leader;
897
898 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
899 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
900
901 /* cycles:G + :u group modifier */
902 evsel = leader = perf_evlist__first(evlist);
903 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
904 TEST_ASSERT_VAL("wrong config",
905 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
906 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
907 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
908 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
909 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
910 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
911 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
912 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
913 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
914 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
915 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
916
917 /* cache-misses:H + :u group modifier */
918 evsel = perf_evsel__next(evsel);
919 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
920 TEST_ASSERT_VAL("wrong config",
921 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
922 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
923 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
924 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
925 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
926 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
927 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
928 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
929 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
930
931 return 0;
932}
933
934static int test__group_gh4(struct perf_evlist *evlist)
935{
936 struct perf_evsel *evsel, *leader;
937
938 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
939 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
940
941 /* cycles:G + :uG group modifier */
942 evsel = leader = perf_evlist__first(evlist);
943 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
944 TEST_ASSERT_VAL("wrong config",
945 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
946 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
947 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
948 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
949 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
950 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
951 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
952 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
953 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
954 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
955 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
956
957 /* cache-misses:H + :uG group modifier */
958 evsel = perf_evsel__next(evsel);
959 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
960 TEST_ASSERT_VAL("wrong config",
961 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
962 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
963 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
964 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
965 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
966 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
967 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
968 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
969 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
970
971 return 0;
972}
973
Jiri Olsa82ce75d2012-12-17 14:08:38 +0100974static int count_tracepoints(void)
975{
976 char events_path[PATH_MAX];
977 struct dirent *events_ent;
978 DIR *events_dir;
979 int cnt = 0;
980
981 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
982 debugfs_find_mountpoint());
983
984 events_dir = opendir(events_path);
985
986 TEST_ASSERT_VAL("Can't open events dir", events_dir);
987
988 while ((events_ent = readdir(events_dir))) {
989 char sys_path[PATH_MAX];
990 struct dirent *sys_ent;
991 DIR *sys_dir;
992
993 if (!strcmp(events_ent->d_name, ".")
994 || !strcmp(events_ent->d_name, "..")
995 || !strcmp(events_ent->d_name, "enable")
996 || !strcmp(events_ent->d_name, "header_event")
997 || !strcmp(events_ent->d_name, "header_page"))
998 continue;
999
1000 scnprintf(sys_path, PATH_MAX, "%s/%s",
1001 events_path, events_ent->d_name);
1002
1003 sys_dir = opendir(sys_path);
1004 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1005
1006 while ((sys_ent = readdir(sys_dir))) {
1007 if (!strcmp(sys_ent->d_name, ".")
1008 || !strcmp(sys_ent->d_name, "..")
1009 || !strcmp(sys_ent->d_name, "enable")
1010 || !strcmp(sys_ent->d_name, "filter"))
1011 continue;
1012
1013 cnt++;
1014 }
1015
1016 closedir(sys_dir);
1017 }
1018
1019 closedir(events_dir);
1020 return cnt;
1021}
1022
1023static int test__all_tracepoints(struct perf_evlist *evlist)
1024{
1025 TEST_ASSERT_VAL("wrong events count",
1026 count_tracepoints() == evlist->nr_entries);
1027
1028 return test__checkevent_tracepoint_multi(evlist);
1029}
1030
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001031struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001032 const char *name;
1033 __u32 type;
1034 int (*check)(struct perf_evlist *evlist);
1035};
1036
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001037static struct evlist_test test__events[] = {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001038 [0] = {
1039 .name = "syscalls:sys_enter_open",
1040 .check = test__checkevent_tracepoint,
1041 },
1042 [1] = {
1043 .name = "syscalls:*",
1044 .check = test__checkevent_tracepoint_multi,
1045 },
1046 [2] = {
1047 .name = "r1a",
1048 .check = test__checkevent_raw,
1049 },
1050 [3] = {
1051 .name = "1:1",
1052 .check = test__checkevent_numeric,
1053 },
1054 [4] = {
1055 .name = "instructions",
1056 .check = test__checkevent_symbolic_name,
1057 },
1058 [5] = {
1059 .name = "cycles/period=100000,config2/",
1060 .check = test__checkevent_symbolic_name_config,
1061 },
1062 [6] = {
1063 .name = "faults",
1064 .check = test__checkevent_symbolic_alias,
1065 },
1066 [7] = {
1067 .name = "L1-dcache-load-miss",
1068 .check = test__checkevent_genhw,
1069 },
1070 [8] = {
1071 .name = "mem:0",
1072 .check = test__checkevent_breakpoint,
1073 },
1074 [9] = {
1075 .name = "mem:0:x",
1076 .check = test__checkevent_breakpoint_x,
1077 },
1078 [10] = {
1079 .name = "mem:0:r",
1080 .check = test__checkevent_breakpoint_r,
1081 },
1082 [11] = {
1083 .name = "mem:0:w",
1084 .check = test__checkevent_breakpoint_w,
1085 },
1086 [12] = {
1087 .name = "syscalls:sys_enter_open:k",
1088 .check = test__checkevent_tracepoint_modifier,
1089 },
1090 [13] = {
1091 .name = "syscalls:*:u",
1092 .check = test__checkevent_tracepoint_multi_modifier,
1093 },
1094 [14] = {
1095 .name = "r1a:kp",
1096 .check = test__checkevent_raw_modifier,
1097 },
1098 [15] = {
1099 .name = "1:1:hp",
1100 .check = test__checkevent_numeric_modifier,
1101 },
1102 [16] = {
1103 .name = "instructions:h",
1104 .check = test__checkevent_symbolic_name_modifier,
1105 },
1106 [17] = {
1107 .name = "faults:u",
1108 .check = test__checkevent_symbolic_alias_modifier,
1109 },
1110 [18] = {
1111 .name = "L1-dcache-load-miss:kp",
1112 .check = test__checkevent_genhw_modifier,
1113 },
1114 [19] = {
1115 .name = "mem:0:u",
1116 .check = test__checkevent_breakpoint_modifier,
1117 },
1118 [20] = {
1119 .name = "mem:0:x:k",
1120 .check = test__checkevent_breakpoint_x_modifier,
1121 },
1122 [21] = {
1123 .name = "mem:0:r:hp",
1124 .check = test__checkevent_breakpoint_r_modifier,
1125 },
1126 [22] = {
1127 .name = "mem:0:w:up",
1128 .check = test__checkevent_breakpoint_w_modifier,
1129 },
1130 [23] = {
1131 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
1132 .check = test__checkevent_list,
1133 },
1134 [24] = {
1135 .name = "instructions:G",
1136 .check = test__checkevent_exclude_host_modifier,
1137 },
1138 [25] = {
1139 .name = "instructions:H",
1140 .check = test__checkevent_exclude_guest_modifier,
1141 },
Jiri Olsa75827322012-06-29 09:22:54 +02001142 [26] = {
1143 .name = "mem:0:rw",
1144 .check = test__checkevent_breakpoint_rw,
1145 },
1146 [27] = {
1147 .name = "mem:0:rw:kp",
1148 .check = test__checkevent_breakpoint_rw_modifier,
1149 },
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001150 [28] = {
1151 .name = "{instructions:k,cycles:upp}",
1152 .check = test__group1,
1153 },
1154 [29] = {
1155 .name = "{faults:k,cache-references}:u,cycles:k",
1156 .check = test__group2,
1157 },
1158 [30] = {
1159 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1160 .check = test__group3,
1161 },
1162 [31] = {
1163 .name = "{cycles:u,instructions:kp}:p",
1164 .check = test__group4,
1165 },
1166 [32] = {
1167 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1168 .check = test__group5,
1169 },
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001170 [33] = {
1171 .name = "*:*",
1172 .check = test__all_tracepoints,
1173 },
Jiri Olsa5a30a992013-02-04 10:56:43 +01001174 [34] = {
1175 .name = "{cycles,cache-misses:G}:H",
1176 .check = test__group_gh1,
1177 },
1178 [35] = {
1179 .name = "{cycles,cache-misses:H}:G",
1180 .check = test__group_gh2,
1181 },
1182 [36] = {
1183 .name = "{cycles:G,cache-misses:H}:u",
1184 .check = test__group_gh3,
1185 },
1186 [37] = {
1187 .name = "{cycles:G,cache-misses:H}:uG",
1188 .check = test__group_gh4,
1189 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001190};
1191
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001192static struct evlist_test test__events_pmu[] = {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001193 [0] = {
1194 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1195 .check = test__checkevent_pmu,
1196 },
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001197 [1] = {
1198 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1199 .check = test__checkevent_pmu_name,
1200 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001201};
1202
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001203struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001204 const char *str;
1205 __u32 type;
1206 int (*check)(struct list_head *terms);
1207};
1208
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001209static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001210 [0] = {
1211 .str = "config=10,config1,config2=3,umask=1",
1212 .check = test__checkterms_simple,
1213 },
1214};
1215
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001216static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001217{
1218 struct perf_evlist *evlist;
1219 int ret;
1220
1221 evlist = perf_evlist__new(NULL, NULL);
1222 if (evlist == NULL)
1223 return -ENOMEM;
1224
Jiri Olsad8f7bbc2013-01-15 14:39:51 +01001225 ret = parse_events(evlist, e->name);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001226 if (ret) {
1227 pr_debug("failed to parse event '%s', err %d\n",
1228 e->name, ret);
1229 return ret;
1230 }
1231
1232 ret = e->check(evlist);
1233 perf_evlist__delete(evlist);
1234
1235 return ret;
1236}
1237
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001238static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001239{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001240 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001241 unsigned i;
1242
1243 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001244 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001245
1246 pr_debug("running test %d '%s'\n", i, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001247 ret1 = test_event(e);
1248 if (ret1)
1249 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001250 }
1251
Robert Richter9bfbbc62012-08-21 20:03:15 +02001252 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001253}
1254
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001255static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001256{
1257 struct list_head *terms;
1258 int ret;
1259
1260 terms = malloc(sizeof(*terms));
1261 if (!terms)
1262 return -ENOMEM;
1263
1264 INIT_LIST_HEAD(terms);
1265
1266 ret = parse_events_terms(terms, t->str);
1267 if (ret) {
1268 pr_debug("failed to parse terms '%s', err %d\n",
1269 t->str , ret);
1270 return ret;
1271 }
1272
1273 ret = t->check(terms);
1274 parse_events__free_terms(terms);
1275
1276 return ret;
1277}
1278
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001279static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001280{
1281 int ret = 0;
1282 unsigned i;
1283
1284 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001285 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001286
1287 pr_debug("running test %d '%s'\n", i, t->str);
1288 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001289 if (ret)
1290 break;
1291 }
1292
1293 return ret;
1294}
1295
1296static int test_pmu(void)
1297{
1298 struct stat st;
1299 char path[PATH_MAX];
1300 int ret;
1301
1302 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1303 sysfs_find_mountpoint());
1304
1305 ret = stat(path, &st);
1306 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001307 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001308 return !ret;
1309}
1310
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001311static int test_pmu_events(void)
1312{
1313 struct stat st;
1314 char path[PATH_MAX];
1315 struct dirent *ent;
1316 DIR *dir;
1317 int ret;
1318
1319 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1320 sysfs_find_mountpoint());
1321
1322 ret = stat(path, &st);
1323 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001324 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001325 return 0;
1326 }
1327
1328 dir = opendir(path);
1329 if (!dir) {
1330 pr_debug("can't open pmu event dir");
1331 return -1;
1332 }
1333
1334 while (!ret && (ent = readdir(dir))) {
1335#define MAX_NAME 100
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001336 struct evlist_test e;
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001337 char name[MAX_NAME];
1338
1339 if (!strcmp(ent->d_name, ".") ||
1340 !strcmp(ent->d_name, ".."))
1341 continue;
1342
1343 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1344
1345 e.name = name;
1346 e.check = test__checkevent_pmu_events;
1347
1348 ret = test_event(&e);
1349#undef MAX_NAME
1350 }
1351
1352 closedir(dir);
1353 return ret;
1354}
1355
Jiri Olsac81251e2012-11-10 01:46:51 +01001356int test__parse_events(void)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001357{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001358 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001359
Jiri Olsaebf124f2012-07-04 00:00:47 +02001360#define TEST_EVENTS(tests) \
1361do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001362 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1363 if (!ret2) \
1364 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001365} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001366
Jiri Olsaebf124f2012-07-04 00:00:47 +02001367 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001368
Jiri Olsaebf124f2012-07-04 00:00:47 +02001369 if (test_pmu())
1370 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001371
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001372 if (test_pmu()) {
1373 int ret = test_pmu_events();
1374 if (ret)
1375 return ret;
1376 }
1377
Robert Richter9bfbbc62012-08-21 20:03:15 +02001378 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1379 if (!ret2)
1380 ret2 = ret1;
1381
1382 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001383}