blob: f5b77f5c3192e267c69a786ed92eb10f25ec1a62 [file] [log] [blame]
Jiri Olsaf50246e2012-05-21 09:12:49 +02001#include "parse-events.h"
2#include "evsel.h"
3#include "evlist.h"
Borislav Petkovcd0cfad2013-12-09 17:14:24 +01004#include <api/fs/fs.h>
Jiri Olsac81251e2012-11-10 01:46:51 +01005#include "tests.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02006#include "debug.h"
Namhyung Kim2690c732015-10-20 00:23:49 +09007#include "util.h"
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -03008#include <errno.h>
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -03009#include <linux/kernel.h>
David Howellsd2709c72012-11-19 22:21:03 +000010#include <linux/hw_breakpoint.h>
Jiri Olsa4605eab2015-09-02 09:56:43 +020011#include <api/fs/fs.h>
Arnaldo Carvalho de Melo20a9ed22017-04-18 11:44:58 -030012#include <api/fs/tracing_path.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +020013
Jiri Olsa30f31c02012-08-01 14:48:58 +020014#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
15 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
16
Jiri Olsaf50246e2012-05-21 09:12:49 +020017static int test__checkevent_tracepoint(struct perf_evlist *evlist)
18{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030019 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020020
21 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090022 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020023 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
24 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020025 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020026 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
27 return 0;
28}
29
30static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
31{
32 struct perf_evsel *evsel;
33
34 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090035 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020036
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030037 evlist__for_each_entry(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +020038 TEST_ASSERT_VAL("wrong type",
39 PERF_TYPE_TRACEPOINT == evsel->attr.type);
40 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020041 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020042 TEST_ASSERT_VAL("wrong sample_period",
43 1 == evsel->attr.sample_period);
44 }
45 return 0;
46}
47
48static int test__checkevent_raw(struct perf_evlist *evlist)
49{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030050 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020051
52 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
53 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
54 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
55 return 0;
56}
57
58static int test__checkevent_numeric(struct perf_evlist *evlist)
59{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030060 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020061
62 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
63 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
64 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
65 return 0;
66}
67
68static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
69{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030070 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020071
72 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
73 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
74 TEST_ASSERT_VAL("wrong config",
75 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
76 return 0;
77}
78
79static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
80{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030081 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020082
83 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
84 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
85 TEST_ASSERT_VAL("wrong config",
86 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
Jiri Olsaee4c7582015-07-29 05:42:11 -040087 /*
88 * The period value gets configured within perf_evlist__config,
89 * while this test executes only parse events method.
90 */
Jiri Olsaf50246e2012-05-21 09:12:49 +020091 TEST_ASSERT_VAL("wrong period",
Jiri Olsaee4c7582015-07-29 05:42:11 -040092 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +020093 TEST_ASSERT_VAL("wrong config1",
94 0 == evsel->attr.config1);
95 TEST_ASSERT_VAL("wrong config2",
96 1 == evsel->attr.config2);
97 return 0;
98}
99
100static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
101{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300102 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200103
104 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
105 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
106 TEST_ASSERT_VAL("wrong config",
107 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
108 return 0;
109}
110
111static int test__checkevent_genhw(struct perf_evlist *evlist)
112{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300113 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200114
115 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
116 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
117 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
118 return 0;
119}
120
121static int test__checkevent_breakpoint(struct perf_evlist *evlist)
122{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300123 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200124
125 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
126 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
127 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
128 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
129 evsel->attr.bp_type);
130 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
131 evsel->attr.bp_len);
132 return 0;
133}
134
135static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
136{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300137 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200138
139 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
140 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
141 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
142 TEST_ASSERT_VAL("wrong bp_type",
143 HW_BREAKPOINT_X == evsel->attr.bp_type);
144 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
145 return 0;
146}
147
148static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
149{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300150 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200151
152 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
153 TEST_ASSERT_VAL("wrong type",
154 PERF_TYPE_BREAKPOINT == evsel->attr.type);
155 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
156 TEST_ASSERT_VAL("wrong bp_type",
157 HW_BREAKPOINT_R == evsel->attr.bp_type);
158 TEST_ASSERT_VAL("wrong bp_len",
159 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
160 return 0;
161}
162
163static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
164{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300165 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200166
167 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
168 TEST_ASSERT_VAL("wrong type",
169 PERF_TYPE_BREAKPOINT == evsel->attr.type);
170 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
171 TEST_ASSERT_VAL("wrong bp_type",
172 HW_BREAKPOINT_W == evsel->attr.bp_type);
173 TEST_ASSERT_VAL("wrong bp_len",
174 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
175 return 0;
176}
177
Jiri Olsa75827322012-06-29 09:22:54 +0200178static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
179{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300180 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200181
182 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
183 TEST_ASSERT_VAL("wrong type",
184 PERF_TYPE_BREAKPOINT == evsel->attr.type);
185 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
186 TEST_ASSERT_VAL("wrong bp_type",
187 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
188 TEST_ASSERT_VAL("wrong bp_len",
189 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
190 return 0;
191}
192
Jiri Olsaf50246e2012-05-21 09:12:49 +0200193static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
194{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300195 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200196
197 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
198 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
199 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
200 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
201
202 return test__checkevent_tracepoint(evlist);
203}
204
205static int
206test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
207{
208 struct perf_evsel *evsel;
209
210 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
211
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300212 evlist__for_each_entry(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200213 TEST_ASSERT_VAL("wrong exclude_user",
214 !evsel->attr.exclude_user);
215 TEST_ASSERT_VAL("wrong exclude_kernel",
216 evsel->attr.exclude_kernel);
217 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
218 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
219 }
220
221 return test__checkevent_tracepoint_multi(evlist);
222}
223
224static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
225{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300226 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200227
228 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
229 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
230 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
231 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
232
233 return test__checkevent_raw(evlist);
234}
235
236static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
237{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300238 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200239
240 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
241 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
242 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
243 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
244
245 return test__checkevent_numeric(evlist);
246}
247
248static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
249{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300250 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200251
252 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
253 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
254 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
255 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
256
257 return test__checkevent_symbolic_name(evlist);
258}
259
260static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
261{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300262 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200263
264 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
265 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
266
267 return test__checkevent_symbolic_name(evlist);
268}
269
270static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
271{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300272 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200273
274 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
275 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
276
277 return test__checkevent_symbolic_name(evlist);
278}
279
280static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
281{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300282 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200283
284 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
285 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
286 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
287 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
288
289 return test__checkevent_symbolic_alias(evlist);
290}
291
292static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
293{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300294 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200295
296 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
297 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
298 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
299 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
300
301 return test__checkevent_genhw(evlist);
302}
303
Jiri Olsaa1e12da2015-04-07 23:25:14 +0200304static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist)
305{
306 struct perf_evsel *evsel = perf_evlist__first(evlist);
307
308 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
309 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
310 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
311 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
312 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
313 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
314 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
315
316 return test__checkevent_symbolic_name(evlist);
317}
318
319static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist)
320{
321 struct perf_evsel *evsel = perf_evlist__first(evlist);
322
323 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
324 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
325 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
326 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
327 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
328 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
329 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
330
331 return test__checkevent_symbolic_name(evlist);
332}
333
Jiri Olsaf50246e2012-05-21 09:12:49 +0200334static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
335{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300336 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200337
Jiri Olsaf50246e2012-05-21 09:12:49 +0200338
339 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
340 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
341 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
342 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200343 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200344 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200345
346 return test__checkevent_breakpoint(evlist);
347}
348
349static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
350{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300351 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200352
353 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
354 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
355 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
356 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200357 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200358 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200359
360 return test__checkevent_breakpoint_x(evlist);
361}
362
363static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
364{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300365 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200366
367 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
368 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
369 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
370 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200371 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200372 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200373
374 return test__checkevent_breakpoint_r(evlist);
375}
376
377static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
378{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300379 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200380
381 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
382 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
383 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
384 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200385 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200386 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200387
388 return test__checkevent_breakpoint_w(evlist);
389}
390
Jiri Olsa75827322012-06-29 09:22:54 +0200391static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
392{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300393 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200394
395 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
396 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
397 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
398 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200399 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200400 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200401
402 return test__checkevent_breakpoint_rw(evlist);
403}
404
Jiri Olsaf50246e2012-05-21 09:12:49 +0200405static int test__checkevent_pmu(struct perf_evlist *evlist)
406{
407
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300408 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200409
410 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
411 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
412 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
413 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
414 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
Jiri Olsaee4c7582015-07-29 05:42:11 -0400415 /*
416 * The period value gets configured within perf_evlist__config,
417 * while this test executes only parse events method.
418 */
419 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200420
421 return 0;
422}
423
424static int test__checkevent_list(struct perf_evlist *evlist)
425{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300426 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200427
428 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
429
430 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200431 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
432 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
433 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
434 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
435 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
436 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
437 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
438 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
439
Riku Voipio43f322b2015-04-16 16:52:53 +0300440 /* syscalls:sys_enter_openat:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300441 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200442 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
443 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200444 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200445 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
446 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
447 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
448 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
449 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
450
451 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300452 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200453 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
454 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
455 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
456 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
457 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
458 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
459
460 return 0;
461}
462
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200463static int test__checkevent_pmu_name(struct perf_evlist *evlist)
464{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300465 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200466
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200467 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200468 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
469 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
470 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300471 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200472
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200473 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300474 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200475 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
476 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
477 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200478 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200479 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200480
481 return 0;
482}
483
Kan Liang71ef1502015-08-11 06:30:50 -0400484static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist)
485{
486 struct perf_evsel *evsel = perf_evlist__first(evlist);
487
488 /* cpu/config=1,call-graph=fp,time,period=100000/ */
489 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
490 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
491 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
492 /*
493 * The period, time and callgraph value gets configured
494 * within perf_evlist__config,
495 * while this test executes only parse events method.
496 */
497 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
498 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
499 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
500
501 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
502 evsel = perf_evsel__next(evsel);
503 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
504 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
505 /*
506 * The period, time and callgraph value gets configured
507 * within perf_evlist__config,
508 * while this test executes only parse events method.
509 */
510 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
511 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
512 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
513
514 return 0;
515}
516
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200517static int test__checkevent_pmu_events(struct perf_evlist *evlist)
518{
Arnaldo Carvalho de Melo9a354cd2013-11-13 15:54:30 -0300519 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200520
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200521 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
522 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
523 TEST_ASSERT_VAL("wrong exclude_user",
524 !evsel->attr.exclude_user);
525 TEST_ASSERT_VAL("wrong exclude_kernel",
526 evsel->attr.exclude_kernel);
527 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
528 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Michael Ellermanc9ee7802013-08-06 23:28:06 +1000529 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200530
531 return 0;
532}
533
Kan Liangffe59782014-10-07 11:08:52 -0400534
535static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
536{
537 struct perf_evsel *evsel = perf_evlist__first(evlist);
538
539 /* pmu-event:u */
540 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
541 TEST_ASSERT_VAL("wrong exclude_user",
542 !evsel->attr.exclude_user);
543 TEST_ASSERT_VAL("wrong exclude_kernel",
544 evsel->attr.exclude_kernel);
545 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
546 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
547 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
548
549 /* cpu/pmu-event/u*/
550 evsel = perf_evsel__next(evsel);
551 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
552 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
553 TEST_ASSERT_VAL("wrong exclude_user",
554 !evsel->attr.exclude_user);
555 TEST_ASSERT_VAL("wrong exclude_kernel",
556 evsel->attr.exclude_kernel);
557 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
558 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
559 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
560
561 return 0;
562}
563
Jiri Olsa44293922012-06-15 14:31:42 +0800564static int test__checkterms_simple(struct list_head *terms)
565{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300566 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800567
568 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300569 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800570 TEST_ASSERT_VAL("wrong type term",
571 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
572 TEST_ASSERT_VAL("wrong type val",
573 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
574 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
575 TEST_ASSERT_VAL("wrong config", !term->config);
576
577 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300578 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800579 TEST_ASSERT_VAL("wrong type term",
580 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
581 TEST_ASSERT_VAL("wrong type val",
582 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
583 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
584 TEST_ASSERT_VAL("wrong config", !term->config);
585
586 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300587 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800588 TEST_ASSERT_VAL("wrong type term",
589 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
590 TEST_ASSERT_VAL("wrong type val",
591 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
592 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
593 TEST_ASSERT_VAL("wrong config", !term->config);
594
595 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300596 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800597 TEST_ASSERT_VAL("wrong type term",
598 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
599 TEST_ASSERT_VAL("wrong type val",
600 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
601 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
602 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
603
604 return 0;
605}
606
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200607static int test__group1(struct perf_evlist *evlist)
608{
609 struct perf_evsel *evsel, *leader;
610
611 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900612 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200613
614 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300615 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200616 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
617 TEST_ASSERT_VAL("wrong config",
618 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
619 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
620 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
621 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
622 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
623 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
624 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900625 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900626 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
627 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100628 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200629
630 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300631 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200632 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
633 TEST_ASSERT_VAL("wrong config",
634 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
635 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
636 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
637 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200638 /* use of precise requires exclude_guest */
639 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200640 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
641 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
642 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900643 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100644 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200645
646 return 0;
647}
648
649static int test__group2(struct perf_evlist *evlist)
650{
651 struct perf_evsel *evsel, *leader;
652
653 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900654 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200655
656 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300657 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
659 TEST_ASSERT_VAL("wrong config",
660 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
661 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
662 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
663 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
664 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
665 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
666 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900667 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900668 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
669 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100670 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200671
672 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300673 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200674 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
675 TEST_ASSERT_VAL("wrong config",
676 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
677 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
678 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
679 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100680 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200681 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
682 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
683 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900684 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100685 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200686
687 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300688 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200689 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
690 TEST_ASSERT_VAL("wrong config",
691 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
692 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
693 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
694 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
695 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
696 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
697 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900698 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100699 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200700
701 return 0;
702}
703
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300704static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200705{
706 struct perf_evsel *evsel, *leader;
707
708 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900709 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200710
Riku Voipio43f322b2015-04-16 16:52:53 +0300711 /* group1 syscalls:sys_enter_openat:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300712 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200713 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
714 TEST_ASSERT_VAL("wrong sample_type",
715 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
716 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
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, "group1"));
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 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300731 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200732 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
733 TEST_ASSERT_VAL("wrong config",
734 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
735 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
736 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
737 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200738 /* use of precise requires exclude_guest */
739 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200740 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
741 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
742 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
743 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900744 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100745 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200746
747 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300748 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200749 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
750 TEST_ASSERT_VAL("wrong config",
751 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
752 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
753 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
754 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
755 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
756 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
757 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900758 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200759 TEST_ASSERT_VAL("wrong group name",
760 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900761 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
762 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100763 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200764
765 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300766 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200767 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
768 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
769 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
770 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
771 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
772 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
773 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
774 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
775 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900776 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100777 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200778
779 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300780 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200781 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
782 TEST_ASSERT_VAL("wrong config",
783 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
784 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
785 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
786 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
787 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
788 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
789 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900790 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100791 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200792
793 return 0;
794}
795
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300796static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200797{
798 struct perf_evsel *evsel, *leader;
799
800 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900801 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200802
803 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300804 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200805 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
806 TEST_ASSERT_VAL("wrong config",
807 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
808 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
809 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
810 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200811 /* use of precise requires exclude_guest */
812 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200813 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
814 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
815 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900816 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900817 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
818 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100819 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200820
821 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300822 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200823 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
824 TEST_ASSERT_VAL("wrong config",
825 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
826 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
827 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
828 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200829 /* use of precise requires exclude_guest */
830 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200831 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
832 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
833 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900834 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100835 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200836
837 return 0;
838}
839
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300840static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200841{
842 struct perf_evsel *evsel, *leader;
843
844 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900845 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200846
847 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300848 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200849 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
850 TEST_ASSERT_VAL("wrong config",
851 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
852 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
853 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
854 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
855 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
856 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
857 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
858 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900859 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900860 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
861 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100862 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200863
864 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300865 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200866 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
867 TEST_ASSERT_VAL("wrong config",
868 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
869 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
870 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
871 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
872 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
873 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
874 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
875 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900876 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100877 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200878
879 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300880 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200881 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
882 TEST_ASSERT_VAL("wrong config",
883 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
884 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
885 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
886 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
887 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
888 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
889 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
890 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900891 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900892 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
893 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100894 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200895
896 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300897 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200898 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
899 TEST_ASSERT_VAL("wrong config",
900 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
901 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
902 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
903 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
904 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
905 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
906 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
907 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900908 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200909
910 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300911 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200912 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
913 TEST_ASSERT_VAL("wrong config",
914 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
915 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
916 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
917 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
918 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
919 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
920 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900921 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200922
923 return 0;
924}
925
Jiri Olsa5a30a992013-02-04 10:56:43 +0100926static int test__group_gh1(struct perf_evlist *evlist)
927{
928 struct perf_evsel *evsel, *leader;
929
930 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
931 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
932
933 /* cycles + :H group modifier */
934 evsel = leader = perf_evlist__first(evlist);
935 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
936 TEST_ASSERT_VAL("wrong config",
937 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
938 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
939 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
940 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
941 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
942 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
943 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
944 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
945 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
946 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
947 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
948
949 /* cache-misses:G + :H group modifier */
950 evsel = perf_evsel__next(evsel);
951 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
952 TEST_ASSERT_VAL("wrong config",
953 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
954 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
955 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
956 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
957 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
958 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
959 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
960 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
961 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
962
963 return 0;
964}
965
966static int test__group_gh2(struct perf_evlist *evlist)
967{
968 struct perf_evsel *evsel, *leader;
969
970 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
971 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
972
973 /* cycles + :G group modifier */
974 evsel = leader = perf_evlist__first(evlist);
975 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
976 TEST_ASSERT_VAL("wrong config",
977 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
978 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
979 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
980 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
981 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
982 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
983 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
984 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
985 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
986 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
987 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
988
989 /* cache-misses:H + :G group modifier */
990 evsel = perf_evsel__next(evsel);
991 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
992 TEST_ASSERT_VAL("wrong config",
993 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
994 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
995 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
996 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
997 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
998 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
999 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1000 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1001 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1002
1003 return 0;
1004}
1005
1006static int test__group_gh3(struct perf_evlist *evlist)
1007{
1008 struct perf_evsel *evsel, *leader;
1009
1010 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1011 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1012
1013 /* cycles:G + :u group modifier */
1014 evsel = leader = perf_evlist__first(evlist);
1015 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1016 TEST_ASSERT_VAL("wrong config",
1017 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1018 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1019 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1020 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1021 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1022 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1023 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1024 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1025 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1026 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1027 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1028
1029 /* cache-misses:H + :u group modifier */
1030 evsel = perf_evsel__next(evsel);
1031 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1032 TEST_ASSERT_VAL("wrong config",
1033 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1034 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1035 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1036 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1037 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1038 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1039 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1040 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1041 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1042
1043 return 0;
1044}
1045
1046static int test__group_gh4(struct perf_evlist *evlist)
1047{
1048 struct perf_evsel *evsel, *leader;
1049
1050 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1051 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1052
1053 /* cycles:G + :uG group modifier */
1054 evsel = leader = perf_evlist__first(evlist);
1055 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1056 TEST_ASSERT_VAL("wrong config",
1057 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1058 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1059 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1060 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1061 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1062 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1063 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1064 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1065 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1066 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1067 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1068
1069 /* cache-misses:H + :uG group modifier */
1070 evsel = perf_evsel__next(evsel);
1071 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1072 TEST_ASSERT_VAL("wrong config",
1073 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1074 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1075 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1076 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1077 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1078 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1079 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1080 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1081 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1082
1083 return 0;
1084}
1085
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001086static int test__leader_sample1(struct perf_evlist *evlist)
1087{
1088 struct perf_evsel *evsel, *leader;
1089
1090 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1091
1092 /* cycles - sampling group leader */
1093 evsel = leader = perf_evlist__first(evlist);
1094 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1095 TEST_ASSERT_VAL("wrong config",
1096 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1097 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1098 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1099 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1100 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1101 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1102 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1103 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1104 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1105 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1106
1107 /* cache-misses - not sampling */
1108 evsel = perf_evsel__next(evsel);
1109 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1110 TEST_ASSERT_VAL("wrong config",
1111 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1112 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1113 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1114 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1115 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1116 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1117 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1118 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1119 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1120
1121 /* branch-misses - not sampling */
1122 evsel = perf_evsel__next(evsel);
1123 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1124 TEST_ASSERT_VAL("wrong config",
1125 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1126 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1127 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1128 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1129 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1130 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1131 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1132 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1133 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1134 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1135
1136 return 0;
1137}
1138
1139static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1140{
1141 struct perf_evsel *evsel, *leader;
1142
1143 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1144
1145 /* instructions - sampling group leader */
1146 evsel = leader = perf_evlist__first(evlist);
1147 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1148 TEST_ASSERT_VAL("wrong config",
1149 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1150 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1151 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1152 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1153 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1154 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1155 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1156 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1157 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1158 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1159
1160 /* branch-misses - not sampling */
1161 evsel = perf_evsel__next(evsel);
1162 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1163 TEST_ASSERT_VAL("wrong config",
1164 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1165 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1166 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1167 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1168 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1169 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1170 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1171 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1172 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1173 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1174
1175 return 0;
1176}
1177
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001178static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1179{
1180 struct perf_evsel *evsel = perf_evlist__first(evlist);
1181
1182 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1183 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1184 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1185 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
1186 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1187
1188 return test__checkevent_symbolic_name(evlist);
1189}
1190
1191static int test__pinned_group(struct perf_evlist *evlist)
1192{
1193 struct perf_evsel *evsel, *leader;
1194
1195 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1196
1197 /* cycles - group leader */
1198 evsel = leader = perf_evlist__first(evlist);
1199 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1200 TEST_ASSERT_VAL("wrong config",
1201 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1202 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1203 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1204 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1205
1206 /* cache-misses - can not be pinned, but will go on with the leader */
1207 evsel = perf_evsel__next(evsel);
1208 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1209 TEST_ASSERT_VAL("wrong config",
1210 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1211 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1212
1213 /* branch-misses - ditto */
1214 evsel = perf_evsel__next(evsel);
1215 TEST_ASSERT_VAL("wrong config",
1216 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1217 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1218
1219 return 0;
1220}
1221
Jacob Shinec323982014-05-29 17:26:52 +02001222static int test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1223{
1224 struct perf_evsel *evsel = perf_evlist__first(evlist);
1225
1226 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1227 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1228 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1229 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1230 evsel->attr.bp_type);
1231 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1232 evsel->attr.bp_len);
1233
1234 return 0;
1235}
1236
1237static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1238{
1239 struct perf_evsel *evsel = perf_evlist__first(evlist);
1240
1241 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1242 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1243 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1244 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1245 evsel->attr.bp_type);
1246 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1247 evsel->attr.bp_len);
1248
1249 return 0;
1250}
1251
1252static int
1253test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1254{
1255 struct perf_evsel *evsel = perf_evlist__first(evlist);
1256
1257 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1258 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1259 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1260 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1261
1262 return test__checkevent_breakpoint_rw(evlist);
1263}
1264
Jiri Olsaddd83c92015-10-05 20:06:06 +02001265static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
1266{
1267 struct perf_evsel *evsel = perf_evlist__first(evlist);
1268
1269 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1270 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
1271 TEST_ASSERT_VAL("wrong config",
1272 PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config);
1273 return 0;
1274}
1275
Wang Nan10bf3582016-02-19 11:44:00 +00001276static int test__checkevent_config_symbol(struct perf_evlist *evlist)
1277{
1278 struct perf_evsel *evsel = perf_evlist__first(evlist);
1279
1280 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1281 return 0;
1282}
1283
1284static int test__checkevent_config_raw(struct perf_evlist *evlist)
1285{
1286 struct perf_evsel *evsel = perf_evlist__first(evlist);
1287
1288 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1289 return 0;
1290}
1291
1292static int test__checkevent_config_num(struct perf_evlist *evlist)
1293{
1294 struct perf_evsel *evsel = perf_evlist__first(evlist);
1295
1296 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1297 return 0;
1298}
1299
Wang Nan43d0b972016-02-19 11:44:01 +00001300static int test__checkevent_config_cache(struct perf_evlist *evlist)
1301{
1302 struct perf_evsel *evsel = perf_evlist__first(evlist);
1303
1304 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1305 return 0;
1306}
Wang Nan10bf3582016-02-19 11:44:00 +00001307
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001308static int count_tracepoints(void)
1309{
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001310 struct dirent *events_ent;
1311 DIR *events_dir;
1312 int cnt = 0;
1313
Jiri Olsafbf99622015-09-02 09:56:45 +02001314 events_dir = opendir(tracing_events_path);
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001315
1316 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1317
1318 while ((events_ent = readdir(events_dir))) {
1319 char sys_path[PATH_MAX];
1320 struct dirent *sys_ent;
1321 DIR *sys_dir;
1322
1323 if (!strcmp(events_ent->d_name, ".")
1324 || !strcmp(events_ent->d_name, "..")
1325 || !strcmp(events_ent->d_name, "enable")
1326 || !strcmp(events_ent->d_name, "header_event")
1327 || !strcmp(events_ent->d_name, "header_page"))
1328 continue;
1329
1330 scnprintf(sys_path, PATH_MAX, "%s/%s",
Jiri Olsafbf99622015-09-02 09:56:45 +02001331 tracing_events_path, events_ent->d_name);
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001332
1333 sys_dir = opendir(sys_path);
1334 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1335
1336 while ((sys_ent = readdir(sys_dir))) {
1337 if (!strcmp(sys_ent->d_name, ".")
1338 || !strcmp(sys_ent->d_name, "..")
1339 || !strcmp(sys_ent->d_name, "enable")
1340 || !strcmp(sys_ent->d_name, "filter"))
1341 continue;
1342
1343 cnt++;
1344 }
1345
1346 closedir(sys_dir);
1347 }
1348
1349 closedir(events_dir);
1350 return cnt;
1351}
1352
1353static int test__all_tracepoints(struct perf_evlist *evlist)
1354{
1355 TEST_ASSERT_VAL("wrong events count",
1356 count_tracepoints() == evlist->nr_entries);
1357
1358 return test__checkevent_tracepoint_multi(evlist);
1359}
1360
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001361struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001362 const char *name;
1363 __u32 type;
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001364 const int id;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001365 int (*check)(struct perf_evlist *evlist);
1366};
1367
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001368static struct evlist_test test__events[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001369 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001370 .name = "syscalls:sys_enter_openat",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001371 .check = test__checkevent_tracepoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001372 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001373 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001374 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001375 .name = "syscalls:*",
1376 .check = test__checkevent_tracepoint_multi,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001377 .id = 1,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001378 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001379 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001380 .name = "r1a",
1381 .check = test__checkevent_raw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001382 .id = 2,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001383 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001384 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001385 .name = "1:1",
1386 .check = test__checkevent_numeric,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001387 .id = 3,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001388 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001389 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001390 .name = "instructions",
1391 .check = test__checkevent_symbolic_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001392 .id = 4,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001393 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001394 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001395 .name = "cycles/period=100000,config2/",
1396 .check = test__checkevent_symbolic_name_config,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001397 .id = 5,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001398 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001399 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001400 .name = "faults",
1401 .check = test__checkevent_symbolic_alias,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001402 .id = 6,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001403 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001404 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001405 .name = "L1-dcache-load-miss",
1406 .check = test__checkevent_genhw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001407 .id = 7,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001408 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001409 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001410 .name = "mem:0",
1411 .check = test__checkevent_breakpoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001412 .id = 8,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001413 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001414 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001415 .name = "mem:0:x",
1416 .check = test__checkevent_breakpoint_x,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001417 .id = 9,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001418 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001419 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001420 .name = "mem:0:r",
1421 .check = test__checkevent_breakpoint_r,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001422 .id = 10,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001423 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001424 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001425 .name = "mem:0:w",
1426 .check = test__checkevent_breakpoint_w,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001427 .id = 11,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001428 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001429 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001430 .name = "syscalls:sys_enter_openat:k",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001431 .check = test__checkevent_tracepoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001432 .id = 12,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001433 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001434 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001435 .name = "syscalls:*:u",
1436 .check = test__checkevent_tracepoint_multi_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001437 .id = 13,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001438 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001439 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001440 .name = "r1a:kp",
1441 .check = test__checkevent_raw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001442 .id = 14,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001443 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001444 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001445 .name = "1:1:hp",
1446 .check = test__checkevent_numeric_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001447 .id = 15,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001448 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001449 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001450 .name = "instructions:h",
1451 .check = test__checkevent_symbolic_name_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001452 .id = 16,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001453 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001454 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001455 .name = "faults:u",
1456 .check = test__checkevent_symbolic_alias_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001457 .id = 17,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001458 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001459 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001460 .name = "L1-dcache-load-miss:kp",
1461 .check = test__checkevent_genhw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001462 .id = 18,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001463 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001464 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001465 .name = "mem:0:u",
1466 .check = test__checkevent_breakpoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001467 .id = 19,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001468 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001469 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001470 .name = "mem:0:x:k",
1471 .check = test__checkevent_breakpoint_x_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001472 .id = 20,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001473 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001474 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001475 .name = "mem:0:r:hp",
1476 .check = test__checkevent_breakpoint_r_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001477 .id = 21,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001478 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001479 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001480 .name = "mem:0:w:up",
1481 .check = test__checkevent_breakpoint_w_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001482 .id = 22,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001483 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001484 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001485 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001486 .check = test__checkevent_list,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001487 .id = 23,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001488 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001489 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001490 .name = "instructions:G",
1491 .check = test__checkevent_exclude_host_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001492 .id = 24,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001493 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001494 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001495 .name = "instructions:H",
1496 .check = test__checkevent_exclude_guest_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001497 .id = 25,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001498 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001499 {
Jiri Olsa75827322012-06-29 09:22:54 +02001500 .name = "mem:0:rw",
1501 .check = test__checkevent_breakpoint_rw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001502 .id = 26,
Jiri Olsa75827322012-06-29 09:22:54 +02001503 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001504 {
Jiri Olsa75827322012-06-29 09:22:54 +02001505 .name = "mem:0:rw:kp",
1506 .check = test__checkevent_breakpoint_rw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001507 .id = 27,
Jiri Olsa75827322012-06-29 09:22:54 +02001508 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001509 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001510 .name = "{instructions:k,cycles:upp}",
1511 .check = test__group1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001512 .id = 28,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001513 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001514 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001515 .name = "{faults:k,cache-references}:u,cycles:k",
1516 .check = test__group2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001517 .id = 29,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001518 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001519 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001520 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001521 .check = test__group3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001522 .id = 30,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001523 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001524 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001525 .name = "{cycles:u,instructions:kp}:p",
1526 .check = test__group4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001527 .id = 31,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001528 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001529 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001530 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1531 .check = test__group5,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001532 .id = 32,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001533 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001534 {
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001535 .name = "*:*",
1536 .check = test__all_tracepoints,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001537 .id = 33,
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001538 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001539 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001540 .name = "{cycles,cache-misses:G}:H",
1541 .check = test__group_gh1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001542 .id = 34,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001543 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001544 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001545 .name = "{cycles,cache-misses:H}:G",
1546 .check = test__group_gh2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001547 .id = 35,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001548 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001549 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001550 .name = "{cycles:G,cache-misses:H}:u",
1551 .check = test__group_gh3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001552 .id = 36,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001553 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001554 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001555 .name = "{cycles:G,cache-misses:H}:uG",
1556 .check = test__group_gh4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001557 .id = 37,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001558 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001559 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001560 .name = "{cycles,cache-misses,branch-misses}:S",
1561 .check = test__leader_sample1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001562 .id = 38,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001563 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001564 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001565 .name = "{instructions,branch-misses}:Su",
1566 .check = test__leader_sample2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001567 .id = 39,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001568 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001569 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001570 .name = "instructions:uDp",
1571 .check = test__checkevent_pinned_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001572 .id = 40,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001573 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001574 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001575 .name = "{cycles,cache-misses,branch-misses}:D",
1576 .check = test__pinned_group,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001577 .id = 41,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001578 },
Jacob Shinec323982014-05-29 17:26:52 +02001579 {
1580 .name = "mem:0/1",
1581 .check = test__checkevent_breakpoint_len,
1582 .id = 42,
1583 },
1584 {
1585 .name = "mem:0/2:w",
1586 .check = test__checkevent_breakpoint_len_w,
1587 .id = 43,
1588 },
1589 {
1590 .name = "mem:0/4:rw:u",
1591 .check = test__checkevent_breakpoint_len_rw_modifier,
1592 .id = 44
1593 },
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001594#if defined(__s390x__)
1595 {
1596 .name = "kvm-s390:kvm_s390_create_vm",
1597 .check = test__checkevent_tracepoint,
1598 .id = 100,
1599 },
1600#endif
Jiri Olsaa1e12da2015-04-07 23:25:14 +02001601 {
1602 .name = "instructions:I",
1603 .check = test__checkevent_exclude_idle_modifier,
1604 .id = 45,
1605 },
1606 {
1607 .name = "instructions:kIG",
1608 .check = test__checkevent_exclude_idle_modifier_1,
1609 .id = 46,
1610 },
Jiri Olsaddd83c92015-10-05 20:06:06 +02001611 {
1612 .name = "task-clock:P,cycles",
1613 .check = test__checkevent_precise_max_modifier,
1614 .id = 47,
1615 },
Wang Nan10bf3582016-02-19 11:44:00 +00001616 {
1617 .name = "instructions/name=insn/",
1618 .check = test__checkevent_config_symbol,
1619 .id = 48,
1620 },
1621 {
1622 .name = "r1234/name=rawpmu/",
1623 .check = test__checkevent_config_raw,
1624 .id = 49,
1625 },
1626 {
1627 .name = "4:0x6530160/name=numpmu/",
1628 .check = test__checkevent_config_num,
1629 .id = 50,
1630 },
Wang Nan43d0b972016-02-19 11:44:01 +00001631 {
1632 .name = "L1-dcache-misses/name=cachepmu/",
1633 .check = test__checkevent_config_cache,
1634 .id = 51,
1635 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001636};
1637
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001638static struct evlist_test test__events_pmu[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001639 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001640 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1641 .check = test__checkevent_pmu,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001642 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001643 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001644 {
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001645 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1646 .check = test__checkevent_pmu_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001647 .id = 1,
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001648 },
Kan Liang71ef1502015-08-11 06:30:50 -04001649 {
1650 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1651 .check = test__checkevent_pmu_partial_time_callgraph,
1652 .id = 2,
1653 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001654};
1655
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001656struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001657 const char *str;
1658 __u32 type;
1659 int (*check)(struct list_head *terms);
1660};
1661
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001662static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001663 [0] = {
1664 .str = "config=10,config1,config2=3,umask=1",
1665 .check = test__checkterms_simple,
1666 },
1667};
1668
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001669static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001670{
1671 struct perf_evlist *evlist;
1672 int ret;
1673
Namhyung Kim334fe7a2013-03-11 16:43:12 +09001674 evlist = perf_evlist__new();
Jiri Olsaf50246e2012-05-21 09:12:49 +02001675 if (evlist == NULL)
1676 return -ENOMEM;
1677
Jiri Olsab39b8392015-04-22 21:10:16 +02001678 ret = parse_events(evlist, e->name, NULL);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001679 if (ret) {
1680 pr_debug("failed to parse event '%s', err %d\n",
1681 e->name, ret);
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001682 } else {
1683 ret = e->check(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001684 }
Arnaldo Carvalho de Melo48000a12014-12-17 17:24:45 -03001685
Jiri Olsaf50246e2012-05-21 09:12:49 +02001686 perf_evlist__delete(evlist);
1687
1688 return ret;
1689}
1690
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001691static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001692{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001693 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001694 unsigned i;
1695
1696 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001697 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001698
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001699 pr_debug("running test %d '%s'\n", e->id, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001700 ret1 = test_event(e);
1701 if (ret1)
1702 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001703 }
1704
Robert Richter9bfbbc62012-08-21 20:03:15 +02001705 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001706}
1707
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001708static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001709{
David Ahernc549aca2013-07-02 13:27:24 -06001710 struct list_head terms;
Jiri Olsa44293922012-06-15 14:31:42 +08001711 int ret;
1712
David Ahernc549aca2013-07-02 13:27:24 -06001713 INIT_LIST_HEAD(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001714
David Ahernc549aca2013-07-02 13:27:24 -06001715 ret = parse_events_terms(&terms, t->str);
Jiri Olsa44293922012-06-15 14:31:42 +08001716 if (ret) {
1717 pr_debug("failed to parse terms '%s', err %d\n",
1718 t->str , ret);
1719 return ret;
1720 }
1721
David Ahernc549aca2013-07-02 13:27:24 -06001722 ret = t->check(&terms);
Arnaldo Carvalho de Melo682dc242016-02-12 16:48:00 -03001723 parse_events_terms__purge(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001724
1725 return ret;
1726}
1727
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001728static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001729{
1730 int ret = 0;
1731 unsigned i;
1732
1733 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001734 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001735
1736 pr_debug("running test %d '%s'\n", i, t->str);
1737 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001738 if (ret)
1739 break;
1740 }
1741
1742 return ret;
1743}
1744
1745static int test_pmu(void)
1746{
1747 struct stat st;
1748 char path[PATH_MAX];
1749 int ret;
1750
1751 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001752 sysfs__mountpoint());
Jiri Olsaf50246e2012-05-21 09:12:49 +02001753
1754 ret = stat(path, &st);
1755 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001756 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001757 return !ret;
1758}
1759
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001760static int test_pmu_events(void)
1761{
1762 struct stat st;
1763 char path[PATH_MAX];
1764 struct dirent *ent;
1765 DIR *dir;
1766 int ret;
1767
1768 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001769 sysfs__mountpoint());
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001770
1771 ret = stat(path, &st);
1772 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001773 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001774 return 0;
1775 }
1776
1777 dir = opendir(path);
1778 if (!dir) {
1779 pr_debug("can't open pmu event dir");
1780 return -1;
1781 }
1782
1783 while (!ret && (ent = readdir(dir))) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001784 struct evlist_test e;
Arnaldo Carvalho de Melo2e2bbc032017-02-09 14:48:46 -03001785 char name[2 * NAME_MAX + 1 + 12 + 3];
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001786
Andi Kleen17a26342016-06-06 07:36:06 -07001787 /* Names containing . are special and cannot be used directly */
1788 if (strchr(ent->d_name, '.'))
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001789 continue;
1790
Arnaldo Carvalho de Melo2e2bbc032017-02-09 14:48:46 -03001791 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001792
1793 e.name = name;
1794 e.check = test__checkevent_pmu_events;
1795
1796 ret = test_event(&e);
Kan Liangffe59782014-10-07 11:08:52 -04001797 if (ret)
1798 break;
Arnaldo Carvalho de Melo2e2bbc032017-02-09 14:48:46 -03001799 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
Kan Liangffe59782014-10-07 11:08:52 -04001800 e.name = name;
1801 e.check = test__checkevent_pmu_events_mix;
1802 ret = test_event(&e);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001803 }
1804
1805 closedir(dir);
1806 return ret;
1807}
1808
Namhyung Kim2690c732015-10-20 00:23:49 +09001809static void debug_warn(const char *warn, va_list params)
1810{
1811 char msg[1024];
1812
Namhyung Kimbb963e12017-02-17 17:17:38 +09001813 if (verbose <= 0)
Namhyung Kim2690c732015-10-20 00:23:49 +09001814 return;
1815
1816 vsnprintf(msg, sizeof(msg), warn, params);
1817 fprintf(stderr, " Warning: %s\n", msg);
1818}
1819
Arnaldo Carvalho de Melo721a1f52015-11-19 12:01:48 -03001820int test__parse_events(int subtest __maybe_unused)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001821{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001822 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001823
Jiri Olsaebf124f2012-07-04 00:00:47 +02001824#define TEST_EVENTS(tests) \
1825do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001826 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1827 if (!ret2) \
1828 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001829} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001830
Namhyung Kim2690c732015-10-20 00:23:49 +09001831 set_warning_routine(debug_warn);
1832
Jiri Olsaebf124f2012-07-04 00:00:47 +02001833 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001834
Jiri Olsaebf124f2012-07-04 00:00:47 +02001835 if (test_pmu())
1836 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001837
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001838 if (test_pmu()) {
1839 int ret = test_pmu_events();
1840 if (ret)
1841 return ret;
1842 }
1843
Robert Richter9bfbbc62012-08-21 20:03:15 +02001844 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1845 if (!ret2)
1846 ret2 = ret1;
1847
1848 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001849}