blob: 91fbfd593c4aa340ac23c00a890398a331939186 [file] [log] [blame]
Jiri Olsaf50246e2012-05-21 09:12:49 +02001
2#include "parse-events.h"
3#include "evsel.h"
4#include "evlist.h"
Borislav Petkovcd0cfad2013-12-09 17:14:24 +01005#include <api/fs/fs.h>
Jiri Olsac81251e2012-11-10 01:46:51 +01006#include "tests.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02007#include "debug.h"
David Howellsd2709c72012-11-19 22:21:03 +00008#include <linux/hw_breakpoint.h>
Jiri Olsa4605eab2015-09-02 09:56:43 +02009#include <api/fs/fs.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +020010
Jiri Olsa30f31c02012-08-01 14:48:58 +020011#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
12 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
13
Jiri Olsaf50246e2012-05-21 09:12:49 +020014static int test__checkevent_tracepoint(struct perf_evlist *evlist)
15{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030016 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020017
18 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090019 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
21 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020022 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020023 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
24 return 0;
25}
26
27static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
28{
29 struct perf_evsel *evsel;
30
31 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090032 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020033
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -030034 evlist__for_each(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +020035 TEST_ASSERT_VAL("wrong type",
36 PERF_TYPE_TRACEPOINT == evsel->attr.type);
37 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020038 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020039 TEST_ASSERT_VAL("wrong sample_period",
40 1 == evsel->attr.sample_period);
41 }
42 return 0;
43}
44
45static int test__checkevent_raw(struct perf_evlist *evlist)
46{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030047 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020048
49 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
50 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
51 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
52 return 0;
53}
54
55static int test__checkevent_numeric(struct perf_evlist *evlist)
56{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030057 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020058
59 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
60 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
61 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
62 return 0;
63}
64
65static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
66{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030067 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020068
69 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
70 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
71 TEST_ASSERT_VAL("wrong config",
72 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
73 return 0;
74}
75
76static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
77{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030078 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020079
80 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
81 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
82 TEST_ASSERT_VAL("wrong config",
83 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
Jiri Olsaee4c7582015-07-29 05:42:11 -040084 /*
85 * The period value gets configured within perf_evlist__config,
86 * while this test executes only parse events method.
87 */
Jiri Olsaf50246e2012-05-21 09:12:49 +020088 TEST_ASSERT_VAL("wrong period",
Jiri Olsaee4c7582015-07-29 05:42:11 -040089 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +020090 TEST_ASSERT_VAL("wrong config1",
91 0 == evsel->attr.config1);
92 TEST_ASSERT_VAL("wrong config2",
93 1 == evsel->attr.config2);
94 return 0;
95}
96
97static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
98{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030099 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200100
101 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
102 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
103 TEST_ASSERT_VAL("wrong config",
104 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
105 return 0;
106}
107
108static int test__checkevent_genhw(struct perf_evlist *evlist)
109{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300110 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200111
112 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
113 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
114 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
115 return 0;
116}
117
118static int test__checkevent_breakpoint(struct perf_evlist *evlist)
119{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300120 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200121
122 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
123 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
124 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
125 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
126 evsel->attr.bp_type);
127 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
128 evsel->attr.bp_len);
129 return 0;
130}
131
132static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
133{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300134 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200135
136 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
137 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
138 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
139 TEST_ASSERT_VAL("wrong bp_type",
140 HW_BREAKPOINT_X == evsel->attr.bp_type);
141 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
142 return 0;
143}
144
145static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
146{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300147 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200148
149 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
150 TEST_ASSERT_VAL("wrong type",
151 PERF_TYPE_BREAKPOINT == evsel->attr.type);
152 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
153 TEST_ASSERT_VAL("wrong bp_type",
154 HW_BREAKPOINT_R == evsel->attr.bp_type);
155 TEST_ASSERT_VAL("wrong bp_len",
156 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
157 return 0;
158}
159
160static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
161{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300162 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200163
164 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
165 TEST_ASSERT_VAL("wrong type",
166 PERF_TYPE_BREAKPOINT == evsel->attr.type);
167 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
168 TEST_ASSERT_VAL("wrong bp_type",
169 HW_BREAKPOINT_W == evsel->attr.bp_type);
170 TEST_ASSERT_VAL("wrong bp_len",
171 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
172 return 0;
173}
174
Jiri Olsa75827322012-06-29 09:22:54 +0200175static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
176{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300177 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200178
179 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
180 TEST_ASSERT_VAL("wrong type",
181 PERF_TYPE_BREAKPOINT == evsel->attr.type);
182 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
183 TEST_ASSERT_VAL("wrong bp_type",
184 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
185 TEST_ASSERT_VAL("wrong bp_len",
186 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
187 return 0;
188}
189
Jiri Olsaf50246e2012-05-21 09:12:49 +0200190static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
191{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300192 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200193
194 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
195 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
196 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
197 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
198
199 return test__checkevent_tracepoint(evlist);
200}
201
202static int
203test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
204{
205 struct perf_evsel *evsel;
206
207 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
208
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -0300209 evlist__for_each(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200210 TEST_ASSERT_VAL("wrong exclude_user",
211 !evsel->attr.exclude_user);
212 TEST_ASSERT_VAL("wrong exclude_kernel",
213 evsel->attr.exclude_kernel);
214 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
215 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
216 }
217
218 return test__checkevent_tracepoint_multi(evlist);
219}
220
221static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
222{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300223 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200224
225 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
226 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
227 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
228 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
229
230 return test__checkevent_raw(evlist);
231}
232
233static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
234{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300235 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200236
237 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
238 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
239 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
240 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
241
242 return test__checkevent_numeric(evlist);
243}
244
245static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
246{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300247 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200248
249 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
250 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
251 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
252 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
253
254 return test__checkevent_symbolic_name(evlist);
255}
256
257static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
258{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300259 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200260
261 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
262 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
263
264 return test__checkevent_symbolic_name(evlist);
265}
266
267static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
268{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300269 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200270
271 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
272 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
273
274 return test__checkevent_symbolic_name(evlist);
275}
276
277static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
278{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300279 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200280
281 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
282 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
283 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
284 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
285
286 return test__checkevent_symbolic_alias(evlist);
287}
288
289static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
290{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300291 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200292
293 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
294 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
295 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
296 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
297
298 return test__checkevent_genhw(evlist);
299}
300
Jiri Olsaa1e12da2015-04-07 23:25:14 +0200301static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist)
302{
303 struct perf_evsel *evsel = perf_evlist__first(evlist);
304
305 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
306 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
307 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
308 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
309 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
310 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
311 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
312
313 return test__checkevent_symbolic_name(evlist);
314}
315
316static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist)
317{
318 struct perf_evsel *evsel = perf_evlist__first(evlist);
319
320 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
321 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
322 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
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);
327
328 return test__checkevent_symbolic_name(evlist);
329}
330
Jiri Olsaf50246e2012-05-21 09:12:49 +0200331static int test__checkevent_breakpoint_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
Jiri Olsaf50246e2012-05-21 09:12:49 +0200335
336 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
337 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
338 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
339 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200340 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200341 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200342
343 return test__checkevent_breakpoint(evlist);
344}
345
346static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
347{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300348 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200349
350 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
351 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
352 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
353 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200354 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200355 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200356
357 return test__checkevent_breakpoint_x(evlist);
358}
359
360static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
361{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300362 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200363
364 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
365 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
366 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
367 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200368 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200369 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200370
371 return test__checkevent_breakpoint_r(evlist);
372}
373
374static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
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 exclude_user", !evsel->attr.exclude_user);
379 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
380 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
381 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200382 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200383 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200384
385 return test__checkevent_breakpoint_w(evlist);
386}
387
Jiri Olsa75827322012-06-29 09:22:54 +0200388static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
389{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300390 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200391
392 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
393 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
394 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
395 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200396 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200397 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200398
399 return test__checkevent_breakpoint_rw(evlist);
400}
401
Jiri Olsaf50246e2012-05-21 09:12:49 +0200402static int test__checkevent_pmu(struct perf_evlist *evlist)
403{
404
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300405 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200406
407 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
408 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
409 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
410 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
411 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
Jiri Olsaee4c7582015-07-29 05:42:11 -0400412 /*
413 * The period value gets configured within perf_evlist__config,
414 * while this test executes only parse events method.
415 */
416 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200417
418 return 0;
419}
420
421static int test__checkevent_list(struct perf_evlist *evlist)
422{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300423 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200424
425 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
426
427 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200428 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
429 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
430 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
431 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
432 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
433 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
434 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
435 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
436
Riku Voipio43f322b2015-04-16 16:52:53 +0300437 /* syscalls:sys_enter_openat:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300438 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200439 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
440 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200441 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200442 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
443 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
444 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
445 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
446 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
447
448 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300449 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200450 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
451 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
452 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
453 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
454 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
455 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
456
457 return 0;
458}
459
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200460static int test__checkevent_pmu_name(struct perf_evlist *evlist)
461{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300462 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200463
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200464 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200465 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
466 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
467 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300468 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200469
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200470 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300471 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200472 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
473 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
474 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200475 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200476 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200477
478 return 0;
479}
480
Kan Liang71ef1502015-08-11 06:30:50 -0400481static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist)
482{
483 struct perf_evsel *evsel = perf_evlist__first(evlist);
484
485 /* cpu/config=1,call-graph=fp,time,period=100000/ */
486 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
487 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
488 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
489 /*
490 * The period, time and callgraph value gets configured
491 * within perf_evlist__config,
492 * while this test executes only parse events method.
493 */
494 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
495 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
496 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
497
498 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
499 evsel = perf_evsel__next(evsel);
500 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
501 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
502 /*
503 * The period, time and callgraph value gets configured
504 * within perf_evlist__config,
505 * while this test executes only parse events method.
506 */
507 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
508 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
509 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
510
511 return 0;
512}
513
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200514static int test__checkevent_pmu_events(struct perf_evlist *evlist)
515{
Arnaldo Carvalho de Melo9a354cd2013-11-13 15:54:30 -0300516 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200517
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200518 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
519 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
520 TEST_ASSERT_VAL("wrong exclude_user",
521 !evsel->attr.exclude_user);
522 TEST_ASSERT_VAL("wrong exclude_kernel",
523 evsel->attr.exclude_kernel);
524 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
525 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Michael Ellermanc9ee7802013-08-06 23:28:06 +1000526 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200527
528 return 0;
529}
530
Kan Liangffe59782014-10-07 11:08:52 -0400531
532static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
533{
534 struct perf_evsel *evsel = perf_evlist__first(evlist);
535
536 /* pmu-event:u */
537 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
538 TEST_ASSERT_VAL("wrong exclude_user",
539 !evsel->attr.exclude_user);
540 TEST_ASSERT_VAL("wrong exclude_kernel",
541 evsel->attr.exclude_kernel);
542 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
543 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
544 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
545
546 /* cpu/pmu-event/u*/
547 evsel = perf_evsel__next(evsel);
548 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
549 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
550 TEST_ASSERT_VAL("wrong exclude_user",
551 !evsel->attr.exclude_user);
552 TEST_ASSERT_VAL("wrong exclude_kernel",
553 evsel->attr.exclude_kernel);
554 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
555 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
556 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
557
558 return 0;
559}
560
Jiri Olsa44293922012-06-15 14:31:42 +0800561static int test__checkterms_simple(struct list_head *terms)
562{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300563 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800564
565 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300566 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800567 TEST_ASSERT_VAL("wrong type term",
568 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
569 TEST_ASSERT_VAL("wrong type val",
570 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
571 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
572 TEST_ASSERT_VAL("wrong config", !term->config);
573
574 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300575 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800576 TEST_ASSERT_VAL("wrong type term",
577 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
578 TEST_ASSERT_VAL("wrong type val",
579 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
580 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
581 TEST_ASSERT_VAL("wrong config", !term->config);
582
583 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300584 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800585 TEST_ASSERT_VAL("wrong type term",
586 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
587 TEST_ASSERT_VAL("wrong type val",
588 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
589 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
590 TEST_ASSERT_VAL("wrong config", !term->config);
591
592 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300593 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800594 TEST_ASSERT_VAL("wrong type term",
595 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
596 TEST_ASSERT_VAL("wrong type val",
597 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
598 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
599 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
600
601 return 0;
602}
603
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200604static int test__group1(struct perf_evlist *evlist)
605{
606 struct perf_evsel *evsel, *leader;
607
608 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900609 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200610
611 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300612 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200613 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
614 TEST_ASSERT_VAL("wrong config",
615 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
616 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
617 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
618 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
619 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
620 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
621 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900622 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900623 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
624 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100625 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200626
627 /* cycles:upp */
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 == 2);
639 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900640 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100641 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200642
643 return 0;
644}
645
646static int test__group2(struct perf_evlist *evlist)
647{
648 struct perf_evsel *evsel, *leader;
649
650 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900651 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200652
653 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300654 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200655 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
656 TEST_ASSERT_VAL("wrong config",
657 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
658 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
659 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
660 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
661 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
662 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
663 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900664 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900665 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
666 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100667 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200668
669 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300670 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200671 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
672 TEST_ASSERT_VAL("wrong config",
673 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
674 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
675 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
676 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100677 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200678 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
679 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
680 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900681 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100682 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200683
684 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300685 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200686 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
687 TEST_ASSERT_VAL("wrong config",
688 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
689 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
690 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
691 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
692 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
693 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
694 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900695 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100696 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200697
698 return 0;
699}
700
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300701static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200702{
703 struct perf_evsel *evsel, *leader;
704
705 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900706 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200707
Riku Voipio43f322b2015-04-16 16:52:53 +0300708 /* group1 syscalls:sys_enter_openat:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300709 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200710 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
711 TEST_ASSERT_VAL("wrong sample_type",
712 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
713 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
714 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
715 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
716 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
717 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
718 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
719 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900720 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200721 TEST_ASSERT_VAL("wrong group name",
722 !strcmp(leader->group_name, "group1"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900723 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
724 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100725 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200726
727 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300728 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200729 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
730 TEST_ASSERT_VAL("wrong config",
731 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
732 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
733 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
734 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200735 /* use of precise requires exclude_guest */
736 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200737 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
738 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
739 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
740 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900741 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100742 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200743
744 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300745 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200746 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
747 TEST_ASSERT_VAL("wrong config",
748 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
749 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
750 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
751 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
752 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
753 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
754 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
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 TEST_ASSERT_VAL("wrong group name",
757 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900758 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
759 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100760 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200761
762 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300763 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200764 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
765 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
766 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
767 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
768 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
769 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
770 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
771 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
772 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900773 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100774 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200775
776 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300777 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200778 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
779 TEST_ASSERT_VAL("wrong config",
780 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
781 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
782 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
783 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
784 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
785 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
786 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900787 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100788 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200789
790 return 0;
791}
792
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300793static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200794{
795 struct perf_evsel *evsel, *leader;
796
797 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900798 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200799
800 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300801 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200802 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
803 TEST_ASSERT_VAL("wrong config",
804 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
805 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
806 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
807 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200808 /* use of precise requires exclude_guest */
809 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200810 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
811 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
812 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900813 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900814 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
815 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100816 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200817
818 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300819 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200820 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
821 TEST_ASSERT_VAL("wrong config",
822 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
823 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
824 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
825 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200826 /* use of precise requires exclude_guest */
827 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200828 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
829 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
830 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900831 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100832 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200833
834 return 0;
835}
836
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300837static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200838{
839 struct perf_evsel *evsel, *leader;
840
841 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900842 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200843
844 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300845 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200846 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
847 TEST_ASSERT_VAL("wrong config",
848 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
849 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
850 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
851 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
852 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
853 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
854 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
855 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900856 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900857 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
858 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100859 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200860
861 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300862 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200863 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
864 TEST_ASSERT_VAL("wrong config",
865 PERF_COUNT_HW_INSTRUCTIONS == 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 leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900873 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100874 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200875
876 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300877 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200878 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
879 TEST_ASSERT_VAL("wrong config",
880 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
881 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
882 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
883 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
884 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
885 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
886 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
887 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900888 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900889 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
890 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100891 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200892
893 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300894 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200895 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
896 TEST_ASSERT_VAL("wrong config",
897 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
898 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
899 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
900 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
901 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
902 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
903 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
904 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900905 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200906
907 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300908 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200909 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
910 TEST_ASSERT_VAL("wrong config",
911 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
912 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
913 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
914 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
915 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
916 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
917 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900918 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200919
920 return 0;
921}
922
Jiri Olsa5a30a992013-02-04 10:56:43 +0100923static int test__group_gh1(struct perf_evlist *evlist)
924{
925 struct perf_evsel *evsel, *leader;
926
927 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
928 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
929
930 /* cycles + :H group modifier */
931 evsel = leader = perf_evlist__first(evlist);
932 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
933 TEST_ASSERT_VAL("wrong config",
934 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
935 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
936 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
937 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
938 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
939 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
940 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
941 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
942 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
943 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
944 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
945
946 /* cache-misses:G + :H group modifier */
947 evsel = perf_evsel__next(evsel);
948 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
949 TEST_ASSERT_VAL("wrong config",
950 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
951 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
952 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
953 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
954 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
955 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
956 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
957 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
958 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
959
960 return 0;
961}
962
963static int test__group_gh2(struct perf_evlist *evlist)
964{
965 struct perf_evsel *evsel, *leader;
966
967 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
968 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
969
970 /* cycles + :G group modifier */
971 evsel = leader = perf_evlist__first(evlist);
972 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
973 TEST_ASSERT_VAL("wrong config",
974 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
975 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
976 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
977 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
978 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
979 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
980 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
981 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
982 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
983 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
984 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
985
986 /* cache-misses:H + :G group modifier */
987 evsel = perf_evsel__next(evsel);
988 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
989 TEST_ASSERT_VAL("wrong config",
990 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
991 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
992 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
993 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
994 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
995 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
996 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
997 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
998 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
999
1000 return 0;
1001}
1002
1003static int test__group_gh3(struct perf_evlist *evlist)
1004{
1005 struct perf_evsel *evsel, *leader;
1006
1007 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1008 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1009
1010 /* cycles:G + :u group modifier */
1011 evsel = leader = perf_evlist__first(evlist);
1012 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1013 TEST_ASSERT_VAL("wrong config",
1014 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1015 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1016 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1017 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1018 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1019 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1020 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1021 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1022 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1023 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1024 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1025
1026 /* cache-misses:H + :u group modifier */
1027 evsel = perf_evsel__next(evsel);
1028 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1029 TEST_ASSERT_VAL("wrong config",
1030 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1031 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1032 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1033 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1034 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1035 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1036 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1037 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1038 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1039
1040 return 0;
1041}
1042
1043static int test__group_gh4(struct perf_evlist *evlist)
1044{
1045 struct perf_evsel *evsel, *leader;
1046
1047 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1048 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1049
1050 /* cycles:G + :uG group modifier */
1051 evsel = leader = perf_evlist__first(evlist);
1052 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1053 TEST_ASSERT_VAL("wrong config",
1054 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1055 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1056 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1057 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1058 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1059 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1060 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1061 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1062 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1063 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1064 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1065
1066 /* cache-misses:H + :uG group modifier */
1067 evsel = perf_evsel__next(evsel);
1068 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1069 TEST_ASSERT_VAL("wrong config",
1070 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1071 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1072 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1073 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1074 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1075 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1076 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1077 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1078 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1079
1080 return 0;
1081}
1082
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001083static int test__leader_sample1(struct perf_evlist *evlist)
1084{
1085 struct perf_evsel *evsel, *leader;
1086
1087 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1088
1089 /* cycles - sampling group leader */
1090 evsel = leader = perf_evlist__first(evlist);
1091 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1092 TEST_ASSERT_VAL("wrong config",
1093 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1094 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1095 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1096 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1097 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1098 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1099 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1100 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1101 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1102 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1103
1104 /* cache-misses - not sampling */
1105 evsel = perf_evsel__next(evsel);
1106 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1107 TEST_ASSERT_VAL("wrong config",
1108 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1109 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1110 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1111 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1112 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1113 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1114 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1115 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1116 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1117
1118 /* branch-misses - not sampling */
1119 evsel = perf_evsel__next(evsel);
1120 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1121 TEST_ASSERT_VAL("wrong config",
1122 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1123 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1124 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1125 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1126 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1127 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1128 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1129 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1130 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1131 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1132
1133 return 0;
1134}
1135
1136static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1137{
1138 struct perf_evsel *evsel, *leader;
1139
1140 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1141
1142 /* instructions - sampling group leader */
1143 evsel = leader = perf_evlist__first(evlist);
1144 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1145 TEST_ASSERT_VAL("wrong config",
1146 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1147 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1148 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1149 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1150 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1151 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1152 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1153 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1154 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1155 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1156
1157 /* branch-misses - not sampling */
1158 evsel = perf_evsel__next(evsel);
1159 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1160 TEST_ASSERT_VAL("wrong config",
1161 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1162 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1163 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1164 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1165 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1166 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1167 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1168 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1169 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1170 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1171
1172 return 0;
1173}
1174
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001175static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1176{
1177 struct perf_evsel *evsel = perf_evlist__first(evlist);
1178
1179 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1180 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1181 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1182 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
1183 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1184
1185 return test__checkevent_symbolic_name(evlist);
1186}
1187
1188static int test__pinned_group(struct perf_evlist *evlist)
1189{
1190 struct perf_evsel *evsel, *leader;
1191
1192 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1193
1194 /* cycles - group leader */
1195 evsel = leader = perf_evlist__first(evlist);
1196 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1197 TEST_ASSERT_VAL("wrong config",
1198 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1199 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1200 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1201 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1202
1203 /* cache-misses - can not be pinned, but will go on with the leader */
1204 evsel = perf_evsel__next(evsel);
1205 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1206 TEST_ASSERT_VAL("wrong config",
1207 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1208 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1209
1210 /* branch-misses - ditto */
1211 evsel = perf_evsel__next(evsel);
1212 TEST_ASSERT_VAL("wrong config",
1213 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1214 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1215
1216 return 0;
1217}
1218
Jacob Shinec323982014-05-29 17:26:52 +02001219static int test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1220{
1221 struct perf_evsel *evsel = perf_evlist__first(evlist);
1222
1223 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1224 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1225 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1226 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1227 evsel->attr.bp_type);
1228 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1229 evsel->attr.bp_len);
1230
1231 return 0;
1232}
1233
1234static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1235{
1236 struct perf_evsel *evsel = perf_evlist__first(evlist);
1237
1238 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1239 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1240 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1241 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1242 evsel->attr.bp_type);
1243 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1244 evsel->attr.bp_len);
1245
1246 return 0;
1247}
1248
1249static int
1250test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1251{
1252 struct perf_evsel *evsel = perf_evlist__first(evlist);
1253
1254 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1255 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1256 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1257 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1258
1259 return test__checkevent_breakpoint_rw(evlist);
1260}
1261
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001262static int count_tracepoints(void)
1263{
1264 char events_path[PATH_MAX];
1265 struct dirent *events_ent;
Steven Rostedt (Red Hat)23773ca2015-02-02 14:35:07 -05001266 const char *mountpoint;
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001267 DIR *events_dir;
1268 int cnt = 0;
1269
Jiri Olsa4605eab2015-09-02 09:56:43 +02001270 mountpoint = tracefs__mountpoint();
Steven Rostedt (Red Hat)23773ca2015-02-02 14:35:07 -05001271 if (mountpoint) {
1272 scnprintf(events_path, PATH_MAX, "%s/events",
1273 mountpoint);
1274 } else {
Jiri Olsa4605eab2015-09-02 09:56:43 +02001275 mountpoint = debugfs__mountpoint();
Steven Rostedt (Red Hat)23773ca2015-02-02 14:35:07 -05001276 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1277 mountpoint);
1278 }
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001279
1280 events_dir = opendir(events_path);
1281
1282 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1283
1284 while ((events_ent = readdir(events_dir))) {
1285 char sys_path[PATH_MAX];
1286 struct dirent *sys_ent;
1287 DIR *sys_dir;
1288
1289 if (!strcmp(events_ent->d_name, ".")
1290 || !strcmp(events_ent->d_name, "..")
1291 || !strcmp(events_ent->d_name, "enable")
1292 || !strcmp(events_ent->d_name, "header_event")
1293 || !strcmp(events_ent->d_name, "header_page"))
1294 continue;
1295
1296 scnprintf(sys_path, PATH_MAX, "%s/%s",
1297 events_path, events_ent->d_name);
1298
1299 sys_dir = opendir(sys_path);
1300 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1301
1302 while ((sys_ent = readdir(sys_dir))) {
1303 if (!strcmp(sys_ent->d_name, ".")
1304 || !strcmp(sys_ent->d_name, "..")
1305 || !strcmp(sys_ent->d_name, "enable")
1306 || !strcmp(sys_ent->d_name, "filter"))
1307 continue;
1308
1309 cnt++;
1310 }
1311
1312 closedir(sys_dir);
1313 }
1314
1315 closedir(events_dir);
1316 return cnt;
1317}
1318
1319static int test__all_tracepoints(struct perf_evlist *evlist)
1320{
1321 TEST_ASSERT_VAL("wrong events count",
1322 count_tracepoints() == evlist->nr_entries);
1323
1324 return test__checkevent_tracepoint_multi(evlist);
1325}
1326
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001327struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001328 const char *name;
1329 __u32 type;
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001330 const int id;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001331 int (*check)(struct perf_evlist *evlist);
1332};
1333
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001334static struct evlist_test test__events[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001335 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001336 .name = "syscalls:sys_enter_openat",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001337 .check = test__checkevent_tracepoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001338 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001339 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001340 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001341 .name = "syscalls:*",
1342 .check = test__checkevent_tracepoint_multi,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001343 .id = 1,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001344 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001345 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001346 .name = "r1a",
1347 .check = test__checkevent_raw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001348 .id = 2,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001349 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001350 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001351 .name = "1:1",
1352 .check = test__checkevent_numeric,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001353 .id = 3,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001354 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001355 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001356 .name = "instructions",
1357 .check = test__checkevent_symbolic_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001358 .id = 4,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001359 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001360 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001361 .name = "cycles/period=100000,config2/",
1362 .check = test__checkevent_symbolic_name_config,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001363 .id = 5,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001364 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001365 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001366 .name = "faults",
1367 .check = test__checkevent_symbolic_alias,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001368 .id = 6,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001369 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001370 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001371 .name = "L1-dcache-load-miss",
1372 .check = test__checkevent_genhw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001373 .id = 7,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001374 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001375 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001376 .name = "mem:0",
1377 .check = test__checkevent_breakpoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001378 .id = 8,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001379 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001380 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001381 .name = "mem:0:x",
1382 .check = test__checkevent_breakpoint_x,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001383 .id = 9,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001384 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001385 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001386 .name = "mem:0:r",
1387 .check = test__checkevent_breakpoint_r,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001388 .id = 10,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001389 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001390 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001391 .name = "mem:0:w",
1392 .check = test__checkevent_breakpoint_w,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001393 .id = 11,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001394 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001395 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001396 .name = "syscalls:sys_enter_openat:k",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001397 .check = test__checkevent_tracepoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001398 .id = 12,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001399 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001400 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001401 .name = "syscalls:*:u",
1402 .check = test__checkevent_tracepoint_multi_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001403 .id = 13,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001404 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001405 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001406 .name = "r1a:kp",
1407 .check = test__checkevent_raw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001408 .id = 14,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001409 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001410 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001411 .name = "1:1:hp",
1412 .check = test__checkevent_numeric_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001413 .id = 15,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001414 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001415 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001416 .name = "instructions:h",
1417 .check = test__checkevent_symbolic_name_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001418 .id = 16,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001419 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001420 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001421 .name = "faults:u",
1422 .check = test__checkevent_symbolic_alias_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001423 .id = 17,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001424 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001425 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001426 .name = "L1-dcache-load-miss:kp",
1427 .check = test__checkevent_genhw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001428 .id = 18,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001429 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001430 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001431 .name = "mem:0:u",
1432 .check = test__checkevent_breakpoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001433 .id = 19,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001434 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001435 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001436 .name = "mem:0:x:k",
1437 .check = test__checkevent_breakpoint_x_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001438 .id = 20,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001439 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001440 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001441 .name = "mem:0:r:hp",
1442 .check = test__checkevent_breakpoint_r_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001443 .id = 21,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001444 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001445 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001446 .name = "mem:0:w:up",
1447 .check = test__checkevent_breakpoint_w_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001448 .id = 22,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001449 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001450 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001451 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001452 .check = test__checkevent_list,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001453 .id = 23,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001454 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001455 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001456 .name = "instructions:G",
1457 .check = test__checkevent_exclude_host_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001458 .id = 24,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001459 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001460 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001461 .name = "instructions:H",
1462 .check = test__checkevent_exclude_guest_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001463 .id = 25,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001464 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001465 {
Jiri Olsa75827322012-06-29 09:22:54 +02001466 .name = "mem:0:rw",
1467 .check = test__checkevent_breakpoint_rw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001468 .id = 26,
Jiri Olsa75827322012-06-29 09:22:54 +02001469 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001470 {
Jiri Olsa75827322012-06-29 09:22:54 +02001471 .name = "mem:0:rw:kp",
1472 .check = test__checkevent_breakpoint_rw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001473 .id = 27,
Jiri Olsa75827322012-06-29 09:22:54 +02001474 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001475 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001476 .name = "{instructions:k,cycles:upp}",
1477 .check = test__group1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001478 .id = 28,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001479 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001480 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001481 .name = "{faults:k,cache-references}:u,cycles:k",
1482 .check = test__group2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001483 .id = 29,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001484 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001485 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001486 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001487 .check = test__group3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001488 .id = 30,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001489 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001490 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001491 .name = "{cycles:u,instructions:kp}:p",
1492 .check = test__group4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001493 .id = 31,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001494 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001495 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001496 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1497 .check = test__group5,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001498 .id = 32,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001499 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001500 {
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001501 .name = "*:*",
1502 .check = test__all_tracepoints,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001503 .id = 33,
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001504 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001505 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001506 .name = "{cycles,cache-misses:G}:H",
1507 .check = test__group_gh1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001508 .id = 34,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001509 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001510 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001511 .name = "{cycles,cache-misses:H}:G",
1512 .check = test__group_gh2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001513 .id = 35,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001514 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001515 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001516 .name = "{cycles:G,cache-misses:H}:u",
1517 .check = test__group_gh3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001518 .id = 36,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001519 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001520 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001521 .name = "{cycles:G,cache-misses:H}:uG",
1522 .check = test__group_gh4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001523 .id = 37,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001524 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001525 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001526 .name = "{cycles,cache-misses,branch-misses}:S",
1527 .check = test__leader_sample1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001528 .id = 38,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001529 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001530 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001531 .name = "{instructions,branch-misses}:Su",
1532 .check = test__leader_sample2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001533 .id = 39,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001534 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001535 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001536 .name = "instructions:uDp",
1537 .check = test__checkevent_pinned_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001538 .id = 40,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001539 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001540 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001541 .name = "{cycles,cache-misses,branch-misses}:D",
1542 .check = test__pinned_group,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001543 .id = 41,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001544 },
Jacob Shinec323982014-05-29 17:26:52 +02001545 {
1546 .name = "mem:0/1",
1547 .check = test__checkevent_breakpoint_len,
1548 .id = 42,
1549 },
1550 {
1551 .name = "mem:0/2:w",
1552 .check = test__checkevent_breakpoint_len_w,
1553 .id = 43,
1554 },
1555 {
1556 .name = "mem:0/4:rw:u",
1557 .check = test__checkevent_breakpoint_len_rw_modifier,
1558 .id = 44
1559 },
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001560#if defined(__s390x__)
1561 {
1562 .name = "kvm-s390:kvm_s390_create_vm",
1563 .check = test__checkevent_tracepoint,
1564 .id = 100,
1565 },
1566#endif
Jiri Olsaa1e12da2015-04-07 23:25:14 +02001567 {
1568 .name = "instructions:I",
1569 .check = test__checkevent_exclude_idle_modifier,
1570 .id = 45,
1571 },
1572 {
1573 .name = "instructions:kIG",
1574 .check = test__checkevent_exclude_idle_modifier_1,
1575 .id = 46,
1576 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001577};
1578
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001579static struct evlist_test test__events_pmu[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001580 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001581 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1582 .check = test__checkevent_pmu,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001583 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001584 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001585 {
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001586 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1587 .check = test__checkevent_pmu_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001588 .id = 1,
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001589 },
Kan Liang71ef1502015-08-11 06:30:50 -04001590 {
1591 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1592 .check = test__checkevent_pmu_partial_time_callgraph,
1593 .id = 2,
1594 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001595};
1596
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001597struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001598 const char *str;
1599 __u32 type;
1600 int (*check)(struct list_head *terms);
1601};
1602
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001603static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001604 [0] = {
1605 .str = "config=10,config1,config2=3,umask=1",
1606 .check = test__checkterms_simple,
1607 },
1608};
1609
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001610static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001611{
1612 struct perf_evlist *evlist;
1613 int ret;
1614
Namhyung Kim334fe7a2013-03-11 16:43:12 +09001615 evlist = perf_evlist__new();
Jiri Olsaf50246e2012-05-21 09:12:49 +02001616 if (evlist == NULL)
1617 return -ENOMEM;
1618
Jiri Olsab39b8392015-04-22 21:10:16 +02001619 ret = parse_events(evlist, e->name, NULL);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001620 if (ret) {
1621 pr_debug("failed to parse event '%s', err %d\n",
1622 e->name, ret);
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001623 } else {
1624 ret = e->check(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001625 }
Arnaldo Carvalho de Melo48000a12014-12-17 17:24:45 -03001626
Jiri Olsaf50246e2012-05-21 09:12:49 +02001627 perf_evlist__delete(evlist);
1628
1629 return ret;
1630}
1631
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001632static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001633{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001634 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001635 unsigned i;
1636
1637 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001638 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001639
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001640 pr_debug("running test %d '%s'\n", e->id, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001641 ret1 = test_event(e);
1642 if (ret1)
1643 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001644 }
1645
Robert Richter9bfbbc62012-08-21 20:03:15 +02001646 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001647}
1648
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001649static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001650{
David Ahernc549aca2013-07-02 13:27:24 -06001651 struct list_head terms;
Jiri Olsa44293922012-06-15 14:31:42 +08001652 int ret;
1653
David Ahernc549aca2013-07-02 13:27:24 -06001654 INIT_LIST_HEAD(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001655
David Ahernc549aca2013-07-02 13:27:24 -06001656 ret = parse_events_terms(&terms, t->str);
Jiri Olsa44293922012-06-15 14:31:42 +08001657 if (ret) {
1658 pr_debug("failed to parse terms '%s', err %d\n",
1659 t->str , ret);
1660 return ret;
1661 }
1662
David Ahernc549aca2013-07-02 13:27:24 -06001663 ret = t->check(&terms);
1664 parse_events__free_terms(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001665
1666 return ret;
1667}
1668
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001669static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001670{
1671 int ret = 0;
1672 unsigned i;
1673
1674 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001675 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001676
1677 pr_debug("running test %d '%s'\n", i, t->str);
1678 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001679 if (ret)
1680 break;
1681 }
1682
1683 return ret;
1684}
1685
1686static int test_pmu(void)
1687{
1688 struct stat st;
1689 char path[PATH_MAX];
1690 int ret;
1691
1692 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001693 sysfs__mountpoint());
Jiri Olsaf50246e2012-05-21 09:12:49 +02001694
1695 ret = stat(path, &st);
1696 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001697 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001698 return !ret;
1699}
1700
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001701static int test_pmu_events(void)
1702{
1703 struct stat st;
1704 char path[PATH_MAX];
1705 struct dirent *ent;
1706 DIR *dir;
1707 int ret;
1708
1709 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001710 sysfs__mountpoint());
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001711
1712 ret = stat(path, &st);
1713 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001714 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001715 return 0;
1716 }
1717
1718 dir = opendir(path);
1719 if (!dir) {
1720 pr_debug("can't open pmu event dir");
1721 return -1;
1722 }
1723
1724 while (!ret && (ent = readdir(dir))) {
1725#define MAX_NAME 100
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001726 struct evlist_test e;
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001727 char name[MAX_NAME];
1728
1729 if (!strcmp(ent->d_name, ".") ||
1730 !strcmp(ent->d_name, ".."))
1731 continue;
1732
1733 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1734
1735 e.name = name;
1736 e.check = test__checkevent_pmu_events;
1737
1738 ret = test_event(&e);
Kan Liangffe59782014-10-07 11:08:52 -04001739 if (ret)
1740 break;
1741 snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1742 e.name = name;
1743 e.check = test__checkevent_pmu_events_mix;
1744 ret = test_event(&e);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001745#undef MAX_NAME
1746 }
1747
1748 closedir(dir);
1749 return ret;
1750}
1751
Jiri Olsac81251e2012-11-10 01:46:51 +01001752int test__parse_events(void)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001753{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001754 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001755
Jiri Olsaebf124f2012-07-04 00:00:47 +02001756#define TEST_EVENTS(tests) \
1757do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001758 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1759 if (!ret2) \
1760 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001761} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001762
Jiri Olsaebf124f2012-07-04 00:00:47 +02001763 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001764
Jiri Olsaebf124f2012-07-04 00:00:47 +02001765 if (test_pmu())
1766 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001767
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001768 if (test_pmu()) {
1769 int ret = test_pmu_events();
1770 if (ret)
1771 return ret;
1772 }
1773
Robert Richter9bfbbc62012-08-21 20:03:15 +02001774 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1775 if (!ret2)
1776 ret2 = ret1;
1777
1778 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001779}