blob: f65bb89e109ede0031d1b78dc5f3fde062bdd959 [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>
Steven Rostedt (Red Hat)23773ca2015-02-02 14:35:07 -05006#include <api/fs/tracefs.h>
Borislav Petkov553873e2013-12-09 17:14:23 +01007#include <api/fs/debugfs.h>
Jiri Olsac81251e2012-11-10 01:46:51 +01008#include "tests.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02009#include "debug.h"
David Howellsd2709c72012-11-19 22:21:03 +000010#include <linux/hw_breakpoint.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +020011
Jiri Olsa30f31c02012-08-01 14:48:58 +020012#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
13 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
14
Jiri Olsaf50246e2012-05-21 09:12:49 +020015static int test__checkevent_tracepoint(struct perf_evlist *evlist)
16{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030017 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020018
19 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090020 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020021 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
22 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020023 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020024 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
25 return 0;
26}
27
28static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
29{
30 struct perf_evsel *evsel;
31
32 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090033 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020034
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -030035 evlist__for_each(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +020036 TEST_ASSERT_VAL("wrong type",
37 PERF_TYPE_TRACEPOINT == evsel->attr.type);
38 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020039 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020040 TEST_ASSERT_VAL("wrong sample_period",
41 1 == evsel->attr.sample_period);
42 }
43 return 0;
44}
45
46static int test__checkevent_raw(struct perf_evlist *evlist)
47{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030048 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020049
50 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
51 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
52 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
53 return 0;
54}
55
56static int test__checkevent_numeric(struct perf_evlist *evlist)
57{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030058 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020059
60 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
61 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
62 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
63 return 0;
64}
65
66static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
67{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030068 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020069
70 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
71 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
72 TEST_ASSERT_VAL("wrong config",
73 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
74 return 0;
75}
76
77static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
78{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030079 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020080
81 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
82 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
83 TEST_ASSERT_VAL("wrong config",
84 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
Jiri Olsaee4c7582015-07-29 05:42:11 -040085 /*
86 * The period value gets configured within perf_evlist__config,
87 * while this test executes only parse events method.
88 */
Jiri Olsaf50246e2012-05-21 09:12:49 +020089 TEST_ASSERT_VAL("wrong period",
Jiri Olsaee4c7582015-07-29 05:42:11 -040090 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +020091 TEST_ASSERT_VAL("wrong config1",
92 0 == evsel->attr.config1);
93 TEST_ASSERT_VAL("wrong config2",
94 1 == evsel->attr.config2);
95 return 0;
96}
97
98static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
99{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300100 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200101
102 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
103 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
104 TEST_ASSERT_VAL("wrong config",
105 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
106 return 0;
107}
108
109static int test__checkevent_genhw(struct perf_evlist *evlist)
110{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300111 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200112
113 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
115 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
116 return 0;
117}
118
119static int test__checkevent_breakpoint(struct perf_evlist *evlist)
120{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300121 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200122
123 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
124 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
125 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
126 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
127 evsel->attr.bp_type);
128 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
129 evsel->attr.bp_len);
130 return 0;
131}
132
133static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
134{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300135 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200136
137 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
138 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
139 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
140 TEST_ASSERT_VAL("wrong bp_type",
141 HW_BREAKPOINT_X == evsel->attr.bp_type);
142 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
143 return 0;
144}
145
146static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
147{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300148 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200149
150 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
151 TEST_ASSERT_VAL("wrong type",
152 PERF_TYPE_BREAKPOINT == evsel->attr.type);
153 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
154 TEST_ASSERT_VAL("wrong bp_type",
155 HW_BREAKPOINT_R == evsel->attr.bp_type);
156 TEST_ASSERT_VAL("wrong bp_len",
157 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
158 return 0;
159}
160
161static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
162{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300163 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200164
165 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
166 TEST_ASSERT_VAL("wrong type",
167 PERF_TYPE_BREAKPOINT == evsel->attr.type);
168 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
169 TEST_ASSERT_VAL("wrong bp_type",
170 HW_BREAKPOINT_W == evsel->attr.bp_type);
171 TEST_ASSERT_VAL("wrong bp_len",
172 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
173 return 0;
174}
175
Jiri Olsa75827322012-06-29 09:22:54 +0200176static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
177{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300178 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200179
180 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
181 TEST_ASSERT_VAL("wrong type",
182 PERF_TYPE_BREAKPOINT == evsel->attr.type);
183 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
184 TEST_ASSERT_VAL("wrong bp_type",
185 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
186 TEST_ASSERT_VAL("wrong bp_len",
187 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
188 return 0;
189}
190
Jiri Olsaf50246e2012-05-21 09:12:49 +0200191static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
192{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300193 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200194
195 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
196 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
197 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
198 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
199
200 return test__checkevent_tracepoint(evlist);
201}
202
203static int
204test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
205{
206 struct perf_evsel *evsel;
207
208 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
209
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -0300210 evlist__for_each(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200211 TEST_ASSERT_VAL("wrong exclude_user",
212 !evsel->attr.exclude_user);
213 TEST_ASSERT_VAL("wrong exclude_kernel",
214 evsel->attr.exclude_kernel);
215 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
216 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
217 }
218
219 return test__checkevent_tracepoint_multi(evlist);
220}
221
222static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
223{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300224 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200225
226 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
227 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
228 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
229 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
230
231 return test__checkevent_raw(evlist);
232}
233
234static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
235{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300236 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200237
238 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
239 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
240 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
241 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
242
243 return test__checkevent_numeric(evlist);
244}
245
246static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
247{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300248 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200249
250 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
251 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
252 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
253 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
254
255 return test__checkevent_symbolic_name(evlist);
256}
257
258static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
259{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300260 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200261
262 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
263 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
264
265 return test__checkevent_symbolic_name(evlist);
266}
267
268static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
269{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300270 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200271
272 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
273 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
274
275 return test__checkevent_symbolic_name(evlist);
276}
277
278static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
279{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300280 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200281
282 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
283 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
284 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
285 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
286
287 return test__checkevent_symbolic_alias(evlist);
288}
289
290static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
291{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300292 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200293
294 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
295 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
296 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
297 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
298
299 return test__checkevent_genhw(evlist);
300}
301
Jiri Olsaa1e12da2015-04-07 23:25:14 +0200302static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist)
303{
304 struct perf_evsel *evsel = perf_evlist__first(evlist);
305
306 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
307 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
308 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
309 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
310 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
311 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
312 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
313
314 return test__checkevent_symbolic_name(evlist);
315}
316
317static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist)
318{
319 struct perf_evsel *evsel = perf_evlist__first(evlist);
320
321 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
322 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
323 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
324 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
325 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
326 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
327 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
328
329 return test__checkevent_symbolic_name(evlist);
330}
331
Jiri Olsaf50246e2012-05-21 09:12:49 +0200332static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
333{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300334 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200335
Jiri Olsaf50246e2012-05-21 09:12:49 +0200336
337 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
338 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
339 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
340 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200341 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200342 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200343
344 return test__checkevent_breakpoint(evlist);
345}
346
347static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
348{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300349 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200350
351 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
352 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
353 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
354 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200355 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200356 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200357
358 return test__checkevent_breakpoint_x(evlist);
359}
360
361static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
362{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300363 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200364
365 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
366 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
367 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
368 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200369 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200370 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200371
372 return test__checkevent_breakpoint_r(evlist);
373}
374
375static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
376{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300377 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200378
379 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
380 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
381 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
382 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200383 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200384 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200385
386 return test__checkevent_breakpoint_w(evlist);
387}
388
Jiri Olsa75827322012-06-29 09:22:54 +0200389static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
390{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300391 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200392
393 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
394 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
395 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
396 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200397 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200398 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200399
400 return test__checkevent_breakpoint_rw(evlist);
401}
402
Jiri Olsaf50246e2012-05-21 09:12:49 +0200403static int test__checkevent_pmu(struct perf_evlist *evlist)
404{
405
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300406 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200407
408 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
409 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
410 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
411 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
412 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
Jiri Olsaee4c7582015-07-29 05:42:11 -0400413 /*
414 * The period value gets configured within perf_evlist__config,
415 * while this test executes only parse events method.
416 */
417 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200418
419 return 0;
420}
421
422static int test__checkevent_list(struct perf_evlist *evlist)
423{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300424 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200425
426 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
427
428 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200429 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
430 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
431 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
432 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
433 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
434 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
435 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
436 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
437
Riku Voipio43f322b2015-04-16 16:52:53 +0300438 /* syscalls:sys_enter_openat:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300439 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200440 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
441 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200442 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200443 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
444 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
445 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
446 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
447 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
448
449 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300450 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200451 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
452 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
453 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
454 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
455 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
456 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
457
458 return 0;
459}
460
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200461static int test__checkevent_pmu_name(struct perf_evlist *evlist)
462{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300463 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200464
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200465 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200466 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
467 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
468 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300469 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200470
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200471 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300472 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200473 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
474 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
475 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200476 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200477 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200478
479 return 0;
480}
481
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200482static int test__checkevent_pmu_events(struct perf_evlist *evlist)
483{
Arnaldo Carvalho de Melo9a354cd2013-11-13 15:54:30 -0300484 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200485
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200486 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
487 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
488 TEST_ASSERT_VAL("wrong exclude_user",
489 !evsel->attr.exclude_user);
490 TEST_ASSERT_VAL("wrong exclude_kernel",
491 evsel->attr.exclude_kernel);
492 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
493 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Michael Ellermanc9ee7802013-08-06 23:28:06 +1000494 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200495
496 return 0;
497}
498
Kan Liangffe59782014-10-07 11:08:52 -0400499
500static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
501{
502 struct perf_evsel *evsel = perf_evlist__first(evlist);
503
504 /* pmu-event:u */
505 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
506 TEST_ASSERT_VAL("wrong exclude_user",
507 !evsel->attr.exclude_user);
508 TEST_ASSERT_VAL("wrong exclude_kernel",
509 evsel->attr.exclude_kernel);
510 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
511 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
512 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
513
514 /* cpu/pmu-event/u*/
515 evsel = perf_evsel__next(evsel);
516 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
517 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
518 TEST_ASSERT_VAL("wrong exclude_user",
519 !evsel->attr.exclude_user);
520 TEST_ASSERT_VAL("wrong exclude_kernel",
521 evsel->attr.exclude_kernel);
522 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
523 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
524 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
525
526 return 0;
527}
528
Jiri Olsa44293922012-06-15 14:31:42 +0800529static int test__checkterms_simple(struct list_head *terms)
530{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300531 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800532
533 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300534 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800535 TEST_ASSERT_VAL("wrong type term",
536 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
537 TEST_ASSERT_VAL("wrong type val",
538 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
539 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
540 TEST_ASSERT_VAL("wrong config", !term->config);
541
542 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300543 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800544 TEST_ASSERT_VAL("wrong type term",
545 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
546 TEST_ASSERT_VAL("wrong type val",
547 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
548 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
549 TEST_ASSERT_VAL("wrong config", !term->config);
550
551 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300552 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800553 TEST_ASSERT_VAL("wrong type term",
554 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
555 TEST_ASSERT_VAL("wrong type val",
556 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
557 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
558 TEST_ASSERT_VAL("wrong config", !term->config);
559
560 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300561 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800562 TEST_ASSERT_VAL("wrong type term",
563 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
564 TEST_ASSERT_VAL("wrong type val",
565 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
566 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
567 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
568
569 return 0;
570}
571
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200572static int test__group1(struct perf_evlist *evlist)
573{
574 struct perf_evsel *evsel, *leader;
575
576 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900577 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200578
579 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300580 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200581 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
582 TEST_ASSERT_VAL("wrong config",
583 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
584 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
585 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
586 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
587 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
588 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
589 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900590 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900591 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
592 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100593 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200594
595 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300596 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200597 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
598 TEST_ASSERT_VAL("wrong config",
599 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
600 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
601 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
602 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200603 /* use of precise requires exclude_guest */
604 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200605 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
606 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
607 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900608 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100609 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200610
611 return 0;
612}
613
614static int test__group2(struct perf_evlist *evlist)
615{
616 struct perf_evsel *evsel, *leader;
617
618 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900619 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200620
621 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300622 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200623 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
624 TEST_ASSERT_VAL("wrong config",
625 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
626 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
627 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
628 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
629 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
630 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
631 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900632 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900633 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
634 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100635 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200636
637 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300638 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200639 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
640 TEST_ASSERT_VAL("wrong config",
641 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
642 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
643 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
644 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100645 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200646 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
647 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
648 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900649 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100650 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200651
652 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300653 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200654 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
655 TEST_ASSERT_VAL("wrong config",
656 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
657 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
658 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
659 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
660 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
661 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
662 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900663 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100664 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200665
666 return 0;
667}
668
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300669static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200670{
671 struct perf_evsel *evsel, *leader;
672
673 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900674 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200675
Riku Voipio43f322b2015-04-16 16:52:53 +0300676 /* group1 syscalls:sys_enter_openat:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300677 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200678 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
679 TEST_ASSERT_VAL("wrong sample_type",
680 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
681 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
682 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
683 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
684 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
685 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
686 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
687 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900688 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200689 TEST_ASSERT_VAL("wrong group name",
690 !strcmp(leader->group_name, "group1"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900691 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
692 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100693 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200694
695 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300696 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200697 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
698 TEST_ASSERT_VAL("wrong config",
699 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
700 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
701 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
702 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200703 /* use of precise requires exclude_guest */
704 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200705 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
706 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
707 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
708 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900709 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100710 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200711
712 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300713 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200714 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
715 TEST_ASSERT_VAL("wrong config",
716 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
717 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
718 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
719 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
720 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
721 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
722 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900723 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200724 TEST_ASSERT_VAL("wrong group name",
725 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900726 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
727 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100728 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200729
730 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300731 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200732 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
733 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
734 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
735 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
736 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
737 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
738 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
739 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
740 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
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 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300745 evsel = 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_INSTRUCTIONS == 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 Olsaa9f93f92013-02-01 20:37:11 +0100756 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200757
758 return 0;
759}
760
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300761static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200762{
763 struct perf_evsel *evsel, *leader;
764
765 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900766 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200767
768 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300769 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200770 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
771 TEST_ASSERT_VAL("wrong config",
772 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
773 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
774 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
775 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200776 /* use of precise requires exclude_guest */
777 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200778 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
779 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
780 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900781 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900782 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
783 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100784 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200785
786 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300787 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200788 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
789 TEST_ASSERT_VAL("wrong config",
790 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
791 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
792 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
793 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200794 /* use of precise requires exclude_guest */
795 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200796 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
797 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
798 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900799 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100800 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200801
802 return 0;
803}
804
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300805static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200806{
807 struct perf_evsel *evsel, *leader;
808
809 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900810 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200811
812 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300813 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200814 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
815 TEST_ASSERT_VAL("wrong config",
816 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
817 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
818 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
819 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
820 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
821 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
822 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900824 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900825 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
826 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100827 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200828
829 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300830 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200831 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
832 TEST_ASSERT_VAL("wrong config",
833 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
834 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
835 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
836 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
837 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
838 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
839 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
840 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900841 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100842 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200843
844 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300845 evsel = leader = perf_evsel__next(evsel);
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 Olsa905f5ee2012-08-08 12:23:52 +0200874
875 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300876 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200877 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
878 TEST_ASSERT_VAL("wrong config",
879 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
880 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
881 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
882 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
883 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
884 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
885 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900886 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200887
888 return 0;
889}
890
Jiri Olsa5a30a992013-02-04 10:56:43 +0100891static int test__group_gh1(struct perf_evlist *evlist)
892{
893 struct perf_evsel *evsel, *leader;
894
895 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
896 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
897
898 /* cycles + :H group modifier */
899 evsel = leader = perf_evlist__first(evlist);
900 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
901 TEST_ASSERT_VAL("wrong config",
902 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
903 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
904 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
905 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
906 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
907 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
908 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
909 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
910 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
911 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
912 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
913
914 /* cache-misses:G + :H group modifier */
915 evsel = perf_evsel__next(evsel);
916 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
917 TEST_ASSERT_VAL("wrong config",
918 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
919 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
920 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
921 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
922 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
923 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
924 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
925 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
926 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
927
928 return 0;
929}
930
931static int test__group_gh2(struct perf_evlist *evlist)
932{
933 struct perf_evsel *evsel, *leader;
934
935 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
936 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
937
938 /* cycles + :G group modifier */
939 evsel = leader = perf_evlist__first(evlist);
940 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
941 TEST_ASSERT_VAL("wrong config",
942 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
943 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
944 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
945 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
946 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
947 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
948 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
949 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
950 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
951 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
952 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
953
954 /* cache-misses:H + :G group modifier */
955 evsel = perf_evsel__next(evsel);
956 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
957 TEST_ASSERT_VAL("wrong config",
958 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
959 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
960 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
961 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
962 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
963 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
964 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
965 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
966 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
967
968 return 0;
969}
970
971static int test__group_gh3(struct perf_evlist *evlist)
972{
973 struct perf_evsel *evsel, *leader;
974
975 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
976 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
977
978 /* cycles:G + :u group modifier */
979 evsel = leader = perf_evlist__first(evlist);
980 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
981 TEST_ASSERT_VAL("wrong config",
982 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
983 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
984 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
985 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
986 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
987 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
988 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
989 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
990 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
991 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
992 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
993
994 /* cache-misses:H + :u group modifier */
995 evsel = perf_evsel__next(evsel);
996 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
997 TEST_ASSERT_VAL("wrong config",
998 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
999 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1000 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1001 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1002 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1003 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1004 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1005 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1006 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1007
1008 return 0;
1009}
1010
1011static int test__group_gh4(struct perf_evlist *evlist)
1012{
1013 struct perf_evsel *evsel, *leader;
1014
1015 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1016 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1017
1018 /* cycles:G + :uG group modifier */
1019 evsel = leader = perf_evlist__first(evlist);
1020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1021 TEST_ASSERT_VAL("wrong config",
1022 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1023 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1024 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1025 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1026 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1027 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1028 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1029 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1030 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1031 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1032 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1033
1034 /* cache-misses:H + :uG group modifier */
1035 evsel = perf_evsel__next(evsel);
1036 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1037 TEST_ASSERT_VAL("wrong config",
1038 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1039 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1040 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1041 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1042 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1043 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1044 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1045 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1046 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1047
1048 return 0;
1049}
1050
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001051static int test__leader_sample1(struct perf_evlist *evlist)
1052{
1053 struct perf_evsel *evsel, *leader;
1054
1055 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1056
1057 /* cycles - sampling group leader */
1058 evsel = leader = perf_evlist__first(evlist);
1059 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1060 TEST_ASSERT_VAL("wrong config",
1061 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1062 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1063 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1064 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1065 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1066 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1067 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1068 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1069 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1070 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1071
1072 /* cache-misses - not sampling */
1073 evsel = perf_evsel__next(evsel);
1074 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1075 TEST_ASSERT_VAL("wrong config",
1076 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1077 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1078 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1079 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1080 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1081 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1082 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1083 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1084 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1085
1086 /* branch-misses - not sampling */
1087 evsel = perf_evsel__next(evsel);
1088 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1089 TEST_ASSERT_VAL("wrong config",
1090 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1091 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1092 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1093 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1094 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1095 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1096 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1097 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1098 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1099 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1100
1101 return 0;
1102}
1103
1104static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1105{
1106 struct perf_evsel *evsel, *leader;
1107
1108 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1109
1110 /* instructions - sampling group leader */
1111 evsel = leader = perf_evlist__first(evlist);
1112 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1113 TEST_ASSERT_VAL("wrong config",
1114 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1115 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1116 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1117 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1118 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1119 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1120 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1121 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1122 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1123 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1124
1125 /* branch-misses - not sampling */
1126 evsel = perf_evsel__next(evsel);
1127 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1128 TEST_ASSERT_VAL("wrong config",
1129 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1130 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1131 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1132 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1133 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1134 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1135 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1136 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1137 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1138 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1139
1140 return 0;
1141}
1142
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001143static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1144{
1145 struct perf_evsel *evsel = perf_evlist__first(evlist);
1146
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 precise_ip", evsel->attr.precise_ip);
1151 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1152
1153 return test__checkevent_symbolic_name(evlist);
1154}
1155
1156static int test__pinned_group(struct perf_evlist *evlist)
1157{
1158 struct perf_evsel *evsel, *leader;
1159
1160 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1161
1162 /* cycles - group leader */
1163 evsel = leader = perf_evlist__first(evlist);
1164 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1165 TEST_ASSERT_VAL("wrong config",
1166 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1167 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1168 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1169 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1170
1171 /* cache-misses - can not be pinned, but will go on with the leader */
1172 evsel = perf_evsel__next(evsel);
1173 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1174 TEST_ASSERT_VAL("wrong config",
1175 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1176 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1177
1178 /* branch-misses - ditto */
1179 evsel = perf_evsel__next(evsel);
1180 TEST_ASSERT_VAL("wrong config",
1181 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1182 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1183
1184 return 0;
1185}
1186
Jacob Shinec323982014-05-29 17:26:52 +02001187static int test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1188{
1189 struct perf_evsel *evsel = perf_evlist__first(evlist);
1190
1191 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1192 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1193 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1194 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1195 evsel->attr.bp_type);
1196 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1197 evsel->attr.bp_len);
1198
1199 return 0;
1200}
1201
1202static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1203{
1204 struct perf_evsel *evsel = perf_evlist__first(evlist);
1205
1206 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1207 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1208 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1209 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1210 evsel->attr.bp_type);
1211 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1212 evsel->attr.bp_len);
1213
1214 return 0;
1215}
1216
1217static int
1218test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1219{
1220 struct perf_evsel *evsel = perf_evlist__first(evlist);
1221
1222 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1223 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1224 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1225 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1226
1227 return test__checkevent_breakpoint_rw(evlist);
1228}
1229
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001230static int count_tracepoints(void)
1231{
1232 char events_path[PATH_MAX];
1233 struct dirent *events_ent;
Steven Rostedt (Red Hat)23773ca2015-02-02 14:35:07 -05001234 const char *mountpoint;
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001235 DIR *events_dir;
1236 int cnt = 0;
1237
Steven Rostedt (Red Hat)23773ca2015-02-02 14:35:07 -05001238 mountpoint = tracefs_find_mountpoint();
1239 if (mountpoint) {
1240 scnprintf(events_path, PATH_MAX, "%s/events",
1241 mountpoint);
1242 } else {
1243 mountpoint = debugfs_find_mountpoint();
1244 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1245 mountpoint);
1246 }
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001247
1248 events_dir = opendir(events_path);
1249
1250 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1251
1252 while ((events_ent = readdir(events_dir))) {
1253 char sys_path[PATH_MAX];
1254 struct dirent *sys_ent;
1255 DIR *sys_dir;
1256
1257 if (!strcmp(events_ent->d_name, ".")
1258 || !strcmp(events_ent->d_name, "..")
1259 || !strcmp(events_ent->d_name, "enable")
1260 || !strcmp(events_ent->d_name, "header_event")
1261 || !strcmp(events_ent->d_name, "header_page"))
1262 continue;
1263
1264 scnprintf(sys_path, PATH_MAX, "%s/%s",
1265 events_path, events_ent->d_name);
1266
1267 sys_dir = opendir(sys_path);
1268 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1269
1270 while ((sys_ent = readdir(sys_dir))) {
1271 if (!strcmp(sys_ent->d_name, ".")
1272 || !strcmp(sys_ent->d_name, "..")
1273 || !strcmp(sys_ent->d_name, "enable")
1274 || !strcmp(sys_ent->d_name, "filter"))
1275 continue;
1276
1277 cnt++;
1278 }
1279
1280 closedir(sys_dir);
1281 }
1282
1283 closedir(events_dir);
1284 return cnt;
1285}
1286
1287static int test__all_tracepoints(struct perf_evlist *evlist)
1288{
1289 TEST_ASSERT_VAL("wrong events count",
1290 count_tracepoints() == evlist->nr_entries);
1291
1292 return test__checkevent_tracepoint_multi(evlist);
1293}
1294
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001295struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001296 const char *name;
1297 __u32 type;
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001298 const int id;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001299 int (*check)(struct perf_evlist *evlist);
1300};
1301
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001302static struct evlist_test test__events[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001303 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001304 .name = "syscalls:sys_enter_openat",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001305 .check = test__checkevent_tracepoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001306 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001307 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001308 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001309 .name = "syscalls:*",
1310 .check = test__checkevent_tracepoint_multi,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001311 .id = 1,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001312 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001313 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001314 .name = "r1a",
1315 .check = test__checkevent_raw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001316 .id = 2,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001317 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001318 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001319 .name = "1:1",
1320 .check = test__checkevent_numeric,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001321 .id = 3,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001322 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001323 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001324 .name = "instructions",
1325 .check = test__checkevent_symbolic_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001326 .id = 4,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001327 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001328 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001329 .name = "cycles/period=100000,config2/",
1330 .check = test__checkevent_symbolic_name_config,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001331 .id = 5,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001332 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001333 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001334 .name = "faults",
1335 .check = test__checkevent_symbolic_alias,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001336 .id = 6,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001337 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001338 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001339 .name = "L1-dcache-load-miss",
1340 .check = test__checkevent_genhw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001341 .id = 7,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001342 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001343 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001344 .name = "mem:0",
1345 .check = test__checkevent_breakpoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001346 .id = 8,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001347 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001348 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001349 .name = "mem:0:x",
1350 .check = test__checkevent_breakpoint_x,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001351 .id = 9,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001352 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001353 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001354 .name = "mem:0:r",
1355 .check = test__checkevent_breakpoint_r,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001356 .id = 10,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001357 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001358 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001359 .name = "mem:0:w",
1360 .check = test__checkevent_breakpoint_w,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001361 .id = 11,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001362 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001363 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001364 .name = "syscalls:sys_enter_openat:k",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001365 .check = test__checkevent_tracepoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001366 .id = 12,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001367 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001368 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001369 .name = "syscalls:*:u",
1370 .check = test__checkevent_tracepoint_multi_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001371 .id = 13,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001372 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001373 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001374 .name = "r1a:kp",
1375 .check = test__checkevent_raw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001376 .id = 14,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001377 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001378 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001379 .name = "1:1:hp",
1380 .check = test__checkevent_numeric_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001381 .id = 15,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001382 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001383 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001384 .name = "instructions:h",
1385 .check = test__checkevent_symbolic_name_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001386 .id = 16,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001387 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001388 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001389 .name = "faults:u",
1390 .check = test__checkevent_symbolic_alias_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001391 .id = 17,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001392 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001393 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001394 .name = "L1-dcache-load-miss:kp",
1395 .check = test__checkevent_genhw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001396 .id = 18,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001397 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001398 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001399 .name = "mem:0:u",
1400 .check = test__checkevent_breakpoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001401 .id = 19,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001402 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001403 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001404 .name = "mem:0:x:k",
1405 .check = test__checkevent_breakpoint_x_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001406 .id = 20,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001407 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001408 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001409 .name = "mem:0:r:hp",
1410 .check = test__checkevent_breakpoint_r_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001411 .id = 21,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001412 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001413 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001414 .name = "mem:0:w:up",
1415 .check = test__checkevent_breakpoint_w_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001416 .id = 22,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001417 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001418 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001419 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001420 .check = test__checkevent_list,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001421 .id = 23,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001422 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001423 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001424 .name = "instructions:G",
1425 .check = test__checkevent_exclude_host_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001426 .id = 24,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001427 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001428 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001429 .name = "instructions:H",
1430 .check = test__checkevent_exclude_guest_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001431 .id = 25,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001432 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001433 {
Jiri Olsa75827322012-06-29 09:22:54 +02001434 .name = "mem:0:rw",
1435 .check = test__checkevent_breakpoint_rw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001436 .id = 26,
Jiri Olsa75827322012-06-29 09:22:54 +02001437 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001438 {
Jiri Olsa75827322012-06-29 09:22:54 +02001439 .name = "mem:0:rw:kp",
1440 .check = test__checkevent_breakpoint_rw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001441 .id = 27,
Jiri Olsa75827322012-06-29 09:22:54 +02001442 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001443 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001444 .name = "{instructions:k,cycles:upp}",
1445 .check = test__group1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001446 .id = 28,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001447 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001448 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001449 .name = "{faults:k,cache-references}:u,cycles:k",
1450 .check = test__group2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001451 .id = 29,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001452 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001453 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001454 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001455 .check = test__group3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001456 .id = 30,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001457 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001458 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001459 .name = "{cycles:u,instructions:kp}:p",
1460 .check = test__group4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001461 .id = 31,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001462 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001463 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001464 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1465 .check = test__group5,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001466 .id = 32,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001467 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001468 {
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001469 .name = "*:*",
1470 .check = test__all_tracepoints,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001471 .id = 33,
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001472 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001473 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001474 .name = "{cycles,cache-misses:G}:H",
1475 .check = test__group_gh1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001476 .id = 34,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001477 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001478 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001479 .name = "{cycles,cache-misses:H}:G",
1480 .check = test__group_gh2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001481 .id = 35,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001482 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001483 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001484 .name = "{cycles:G,cache-misses:H}:u",
1485 .check = test__group_gh3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001486 .id = 36,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001487 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001488 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001489 .name = "{cycles:G,cache-misses:H}:uG",
1490 .check = test__group_gh4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001491 .id = 37,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001492 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001493 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001494 .name = "{cycles,cache-misses,branch-misses}:S",
1495 .check = test__leader_sample1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001496 .id = 38,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001497 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001498 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001499 .name = "{instructions,branch-misses}:Su",
1500 .check = test__leader_sample2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001501 .id = 39,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001502 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001503 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001504 .name = "instructions:uDp",
1505 .check = test__checkevent_pinned_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001506 .id = 40,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001507 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001508 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001509 .name = "{cycles,cache-misses,branch-misses}:D",
1510 .check = test__pinned_group,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001511 .id = 41,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001512 },
Jacob Shinec323982014-05-29 17:26:52 +02001513 {
1514 .name = "mem:0/1",
1515 .check = test__checkevent_breakpoint_len,
1516 .id = 42,
1517 },
1518 {
1519 .name = "mem:0/2:w",
1520 .check = test__checkevent_breakpoint_len_w,
1521 .id = 43,
1522 },
1523 {
1524 .name = "mem:0/4:rw:u",
1525 .check = test__checkevent_breakpoint_len_rw_modifier,
1526 .id = 44
1527 },
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001528#if defined(__s390x__)
1529 {
1530 .name = "kvm-s390:kvm_s390_create_vm",
1531 .check = test__checkevent_tracepoint,
1532 .id = 100,
1533 },
1534#endif
Jiri Olsaa1e12da2015-04-07 23:25:14 +02001535 {
1536 .name = "instructions:I",
1537 .check = test__checkevent_exclude_idle_modifier,
1538 .id = 45,
1539 },
1540 {
1541 .name = "instructions:kIG",
1542 .check = test__checkevent_exclude_idle_modifier_1,
1543 .id = 46,
1544 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001545};
1546
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001547static struct evlist_test test__events_pmu[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001548 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001549 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1550 .check = test__checkevent_pmu,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001551 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001552 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001553 {
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001554 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1555 .check = test__checkevent_pmu_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001556 .id = 1,
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001557 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001558};
1559
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001560struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001561 const char *str;
1562 __u32 type;
1563 int (*check)(struct list_head *terms);
1564};
1565
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001566static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001567 [0] = {
1568 .str = "config=10,config1,config2=3,umask=1",
1569 .check = test__checkterms_simple,
1570 },
1571};
1572
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001573static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001574{
1575 struct perf_evlist *evlist;
1576 int ret;
1577
Namhyung Kim334fe7a2013-03-11 16:43:12 +09001578 evlist = perf_evlist__new();
Jiri Olsaf50246e2012-05-21 09:12:49 +02001579 if (evlist == NULL)
1580 return -ENOMEM;
1581
Jiri Olsab39b8392015-04-22 21:10:16 +02001582 ret = parse_events(evlist, e->name, NULL);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001583 if (ret) {
1584 pr_debug("failed to parse event '%s', err %d\n",
1585 e->name, ret);
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001586 } else {
1587 ret = e->check(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001588 }
Arnaldo Carvalho de Melo48000a12014-12-17 17:24:45 -03001589
Jiri Olsaf50246e2012-05-21 09:12:49 +02001590 perf_evlist__delete(evlist);
1591
1592 return ret;
1593}
1594
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001595static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001596{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001597 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001598 unsigned i;
1599
1600 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001601 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001602
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001603 pr_debug("running test %d '%s'\n", e->id, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001604 ret1 = test_event(e);
1605 if (ret1)
1606 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001607 }
1608
Robert Richter9bfbbc62012-08-21 20:03:15 +02001609 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001610}
1611
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001612static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001613{
David Ahernc549aca2013-07-02 13:27:24 -06001614 struct list_head terms;
Jiri Olsa44293922012-06-15 14:31:42 +08001615 int ret;
1616
David Ahernc549aca2013-07-02 13:27:24 -06001617 INIT_LIST_HEAD(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001618
David Ahernc549aca2013-07-02 13:27:24 -06001619 ret = parse_events_terms(&terms, t->str);
Jiri Olsa44293922012-06-15 14:31:42 +08001620 if (ret) {
1621 pr_debug("failed to parse terms '%s', err %d\n",
1622 t->str , ret);
1623 return ret;
1624 }
1625
David Ahernc549aca2013-07-02 13:27:24 -06001626 ret = t->check(&terms);
1627 parse_events__free_terms(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001628
1629 return ret;
1630}
1631
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001632static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001633{
1634 int ret = 0;
1635 unsigned i;
1636
1637 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001638 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001639
1640 pr_debug("running test %d '%s'\n", i, t->str);
1641 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001642 if (ret)
1643 break;
1644 }
1645
1646 return ret;
1647}
1648
1649static int test_pmu(void)
1650{
1651 struct stat st;
1652 char path[PATH_MAX];
1653 int ret;
1654
1655 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001656 sysfs__mountpoint());
Jiri Olsaf50246e2012-05-21 09:12:49 +02001657
1658 ret = stat(path, &st);
1659 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001660 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001661 return !ret;
1662}
1663
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001664static int test_pmu_events(void)
1665{
1666 struct stat st;
1667 char path[PATH_MAX];
1668 struct dirent *ent;
1669 DIR *dir;
1670 int ret;
1671
1672 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001673 sysfs__mountpoint());
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001674
1675 ret = stat(path, &st);
1676 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001677 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001678 return 0;
1679 }
1680
1681 dir = opendir(path);
1682 if (!dir) {
1683 pr_debug("can't open pmu event dir");
1684 return -1;
1685 }
1686
1687 while (!ret && (ent = readdir(dir))) {
1688#define MAX_NAME 100
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001689 struct evlist_test e;
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001690 char name[MAX_NAME];
1691
1692 if (!strcmp(ent->d_name, ".") ||
1693 !strcmp(ent->d_name, ".."))
1694 continue;
1695
1696 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1697
1698 e.name = name;
1699 e.check = test__checkevent_pmu_events;
1700
1701 ret = test_event(&e);
Kan Liangffe59782014-10-07 11:08:52 -04001702 if (ret)
1703 break;
1704 snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1705 e.name = name;
1706 e.check = test__checkevent_pmu_events_mix;
1707 ret = test_event(&e);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001708#undef MAX_NAME
1709 }
1710
1711 closedir(dir);
1712 return ret;
1713}
1714
Jiri Olsac81251e2012-11-10 01:46:51 +01001715int test__parse_events(void)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001716{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001717 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001718
Jiri Olsaebf124f2012-07-04 00:00:47 +02001719#define TEST_EVENTS(tests) \
1720do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001721 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1722 if (!ret2) \
1723 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001724} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001725
Jiri Olsaebf124f2012-07-04 00:00:47 +02001726 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001727
Jiri Olsaebf124f2012-07-04 00:00:47 +02001728 if (test_pmu())
1729 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001730
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001731 if (test_pmu()) {
1732 int ret = test_pmu_events();
1733 if (ret)
1734 return ret;
1735 }
1736
Robert Richter9bfbbc62012-08-21 20:03:15 +02001737 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1738 if (!ret2)
1739 ret2 = ret1;
1740
1741 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001742}