blob: 7f2f51f93619c8bef0b491e2bfcc53ea28e6ae4d [file] [log] [blame]
Jiri Olsaf50246e2012-05-21 09:12:49 +02001
2#include "parse-events.h"
3#include "evsel.h"
4#include "evlist.h"
Borislav Petkovcd0cfad2013-12-09 17:14:24 +01005#include <api/fs/fs.h>
Borislav Petkov553873e2013-12-09 17:14:23 +01006#include <api/fs/debugfs.h>
Jiri Olsac81251e2012-11-10 01:46:51 +01007#include "tests.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02008#include "debug.h"
David Howellsd2709c72012-11-19 22:21:03 +00009#include <linux/hw_breakpoint.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +020010
Jiri Olsa30f31c02012-08-01 14:48:58 +020011#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
12 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
13
Jiri Olsaf50246e2012-05-21 09:12:49 +020014static int test__checkevent_tracepoint(struct perf_evlist *evlist)
15{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030016 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020017
18 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090019 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
21 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020022 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020023 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
24 return 0;
25}
26
27static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
28{
29 struct perf_evsel *evsel;
30
31 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090032 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020033
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -030034 evlist__for_each(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +020035 TEST_ASSERT_VAL("wrong type",
36 PERF_TYPE_TRACEPOINT == evsel->attr.type);
37 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020038 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020039 TEST_ASSERT_VAL("wrong sample_period",
40 1 == evsel->attr.sample_period);
41 }
42 return 0;
43}
44
45static int test__checkevent_raw(struct perf_evlist *evlist)
46{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030047 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020048
49 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
50 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
51 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
52 return 0;
53}
54
55static int test__checkevent_numeric(struct perf_evlist *evlist)
56{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030057 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020058
59 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
60 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
61 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
62 return 0;
63}
64
65static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
66{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030067 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020068
69 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
70 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
71 TEST_ASSERT_VAL("wrong config",
72 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
73 return 0;
74}
75
76static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
77{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030078 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020079
80 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
81 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
82 TEST_ASSERT_VAL("wrong config",
83 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
84 TEST_ASSERT_VAL("wrong period",
85 100000 == evsel->attr.sample_period);
86 TEST_ASSERT_VAL("wrong config1",
87 0 == evsel->attr.config1);
88 TEST_ASSERT_VAL("wrong config2",
89 1 == evsel->attr.config2);
90 return 0;
91}
92
93static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
94{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030095 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020096
97 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
98 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
99 TEST_ASSERT_VAL("wrong config",
100 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
101 return 0;
102}
103
104static int test__checkevent_genhw(struct perf_evlist *evlist)
105{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300106 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200107
108 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
109 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
110 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
111 return 0;
112}
113
114static int test__checkevent_breakpoint(struct perf_evlist *evlist)
115{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300116 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200117
118 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
119 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
120 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
121 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
122 evsel->attr.bp_type);
123 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
124 evsel->attr.bp_len);
125 return 0;
126}
127
128static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
129{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300130 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200131
132 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
133 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
134 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
135 TEST_ASSERT_VAL("wrong bp_type",
136 HW_BREAKPOINT_X == evsel->attr.bp_type);
137 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
138 return 0;
139}
140
141static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
142{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300143 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200144
145 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
146 TEST_ASSERT_VAL("wrong type",
147 PERF_TYPE_BREAKPOINT == evsel->attr.type);
148 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
149 TEST_ASSERT_VAL("wrong bp_type",
150 HW_BREAKPOINT_R == evsel->attr.bp_type);
151 TEST_ASSERT_VAL("wrong bp_len",
152 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
153 return 0;
154}
155
156static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
157{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300158 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200159
160 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
161 TEST_ASSERT_VAL("wrong type",
162 PERF_TYPE_BREAKPOINT == evsel->attr.type);
163 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
164 TEST_ASSERT_VAL("wrong bp_type",
165 HW_BREAKPOINT_W == evsel->attr.bp_type);
166 TEST_ASSERT_VAL("wrong bp_len",
167 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
168 return 0;
169}
170
Jiri Olsa75827322012-06-29 09:22:54 +0200171static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
172{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300173 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200174
175 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
176 TEST_ASSERT_VAL("wrong type",
177 PERF_TYPE_BREAKPOINT == evsel->attr.type);
178 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
179 TEST_ASSERT_VAL("wrong bp_type",
180 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
181 TEST_ASSERT_VAL("wrong bp_len",
182 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
183 return 0;
184}
185
Jiri Olsaf50246e2012-05-21 09:12:49 +0200186static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
187{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300188 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200189
190 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
191 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
192 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
193 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
194
195 return test__checkevent_tracepoint(evlist);
196}
197
198static int
199test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
200{
201 struct perf_evsel *evsel;
202
203 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
204
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -0300205 evlist__for_each(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200206 TEST_ASSERT_VAL("wrong exclude_user",
207 !evsel->attr.exclude_user);
208 TEST_ASSERT_VAL("wrong exclude_kernel",
209 evsel->attr.exclude_kernel);
210 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
211 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
212 }
213
214 return test__checkevent_tracepoint_multi(evlist);
215}
216
217static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
218{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300219 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200220
221 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
222 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
223 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
224 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
225
226 return test__checkevent_raw(evlist);
227}
228
229static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
230{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300231 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200232
233 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
234 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
235 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
236 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
237
238 return test__checkevent_numeric(evlist);
239}
240
241static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
242{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300243 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200244
245 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
246 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
247 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
248 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
249
250 return test__checkevent_symbolic_name(evlist);
251}
252
253static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
254{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300255 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200256
257 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
258 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
259
260 return test__checkevent_symbolic_name(evlist);
261}
262
263static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
264{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300265 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200266
267 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
268 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
269
270 return test__checkevent_symbolic_name(evlist);
271}
272
273static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
274{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300275 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200276
277 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
278 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
279 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
280 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
281
282 return test__checkevent_symbolic_alias(evlist);
283}
284
285static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
286{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300287 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200288
289 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
290 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
291 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
292 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
293
294 return test__checkevent_genhw(evlist);
295}
296
297static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
298{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300299 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200300
Jiri Olsaf50246e2012-05-21 09:12:49 +0200301
302 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
303 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
304 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
305 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200306 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200307 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200308
309 return test__checkevent_breakpoint(evlist);
310}
311
312static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
313{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300314 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200315
316 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
317 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
318 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
319 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200320 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200321 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200322
323 return test__checkevent_breakpoint_x(evlist);
324}
325
326static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
327{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300328 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200329
330 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
331 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
332 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
333 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200334 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200335 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200336
337 return test__checkevent_breakpoint_r(evlist);
338}
339
340static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
341{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300342 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200343
344 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
345 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
346 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
347 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200348 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200349 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200350
351 return test__checkevent_breakpoint_w(evlist);
352}
353
Jiri Olsa75827322012-06-29 09:22:54 +0200354static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
355{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300356 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200357
358 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
359 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
360 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
361 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200362 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200363 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200364
365 return test__checkevent_breakpoint_rw(evlist);
366}
367
Jiri Olsaf50246e2012-05-21 09:12:49 +0200368static int test__checkevent_pmu(struct perf_evlist *evlist)
369{
370
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300371 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200372
373 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
374 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
375 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
376 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
377 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
378 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
379
380 return 0;
381}
382
383static int test__checkevent_list(struct perf_evlist *evlist)
384{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300385 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200386
387 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
388
389 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200390 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
391 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
392 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
393 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
394 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
395 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
396 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
397 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
398
399 /* syscalls:sys_enter_open:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300400 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200401 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
402 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200403 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200404 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
405 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
406 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
407 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
408 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
409
410 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300411 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200412 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
413 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
414 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
415 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
416 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
417 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
418
419 return 0;
420}
421
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200422static int test__checkevent_pmu_name(struct perf_evlist *evlist)
423{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300424 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200425
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200426 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200427 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
428 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
429 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300430 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200431
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200432 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300433 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200434 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
435 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
436 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200437 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200438 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200439
440 return 0;
441}
442
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200443static int test__checkevent_pmu_events(struct perf_evlist *evlist)
444{
Arnaldo Carvalho de Melo9a354cd2013-11-13 15:54:30 -0300445 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200446
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200447 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
448 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
449 TEST_ASSERT_VAL("wrong exclude_user",
450 !evsel->attr.exclude_user);
451 TEST_ASSERT_VAL("wrong exclude_kernel",
452 evsel->attr.exclude_kernel);
453 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
454 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Michael Ellermanc9ee7802013-08-06 23:28:06 +1000455 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200456
457 return 0;
458}
459
Kan Liangffe59782014-10-07 11:08:52 -0400460
461static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
462{
463 struct perf_evsel *evsel = perf_evlist__first(evlist);
464
465 /* pmu-event:u */
466 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
467 TEST_ASSERT_VAL("wrong exclude_user",
468 !evsel->attr.exclude_user);
469 TEST_ASSERT_VAL("wrong exclude_kernel",
470 evsel->attr.exclude_kernel);
471 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
472 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
473 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
474
475 /* cpu/pmu-event/u*/
476 evsel = perf_evsel__next(evsel);
477 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
478 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
479 TEST_ASSERT_VAL("wrong exclude_user",
480 !evsel->attr.exclude_user);
481 TEST_ASSERT_VAL("wrong exclude_kernel",
482 evsel->attr.exclude_kernel);
483 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
484 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
485 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
486
487 return 0;
488}
489
Jiri Olsa44293922012-06-15 14:31:42 +0800490static int test__checkterms_simple(struct list_head *terms)
491{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300492 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800493
494 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300495 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800496 TEST_ASSERT_VAL("wrong type term",
497 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
498 TEST_ASSERT_VAL("wrong type val",
499 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
500 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
501 TEST_ASSERT_VAL("wrong config", !term->config);
502
503 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300504 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800505 TEST_ASSERT_VAL("wrong type term",
506 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
507 TEST_ASSERT_VAL("wrong type val",
508 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
509 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
510 TEST_ASSERT_VAL("wrong config", !term->config);
511
512 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300513 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800514 TEST_ASSERT_VAL("wrong type term",
515 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
516 TEST_ASSERT_VAL("wrong type val",
517 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
518 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
519 TEST_ASSERT_VAL("wrong config", !term->config);
520
521 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300522 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800523 TEST_ASSERT_VAL("wrong type term",
524 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
525 TEST_ASSERT_VAL("wrong type val",
526 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
527 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
528 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
529
530 return 0;
531}
532
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200533static int test__group1(struct perf_evlist *evlist)
534{
535 struct perf_evsel *evsel, *leader;
536
537 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900538 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200539
540 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300541 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200542 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
543 TEST_ASSERT_VAL("wrong config",
544 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
545 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
546 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
547 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
548 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
549 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
550 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900551 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900552 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
553 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100554 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200555
556 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300557 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200558 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
559 TEST_ASSERT_VAL("wrong config",
560 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
561 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
562 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
563 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200564 /* use of precise requires exclude_guest */
565 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200566 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
567 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
568 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900569 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100570 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200571
572 return 0;
573}
574
575static int test__group2(struct perf_evlist *evlist)
576{
577 struct perf_evsel *evsel, *leader;
578
579 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900580 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200581
582 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300583 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200584 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
585 TEST_ASSERT_VAL("wrong config",
586 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
587 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
588 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
589 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
590 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
591 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
592 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900593 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900594 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
595 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100596 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200597
598 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300599 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200600 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
601 TEST_ASSERT_VAL("wrong config",
602 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
603 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
604 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
605 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100606 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200607 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
608 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
609 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900610 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100611 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200612
613 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300614 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200615 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
616 TEST_ASSERT_VAL("wrong config",
617 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
618 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
619 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
620 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
621 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
622 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
623 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900624 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100625 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200626
627 return 0;
628}
629
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300630static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200631{
632 struct perf_evsel *evsel, *leader;
633
634 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900635 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200636
637 /* group1 syscalls:sys_enter_open:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300638 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200639 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
640 TEST_ASSERT_VAL("wrong sample_type",
641 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
642 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
643 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
644 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
645 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
646 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
647 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
648 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900649 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200650 TEST_ASSERT_VAL("wrong group name",
651 !strcmp(leader->group_name, "group1"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900652 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
653 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100654 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200655
656 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300657 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
659 TEST_ASSERT_VAL("wrong config",
660 PERF_COUNT_HW_CPU_CYCLES == 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);
Jiri Olsa42be7392012-10-20 18:29:34 +0200664 /* use of precise requires exclude_guest */
665 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200666 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
667 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
668 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
669 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900670 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100671 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200672
673 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300674 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200675 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
676 TEST_ASSERT_VAL("wrong config",
677 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
678 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
679 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
680 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
681 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
682 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
683 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900684 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200685 TEST_ASSERT_VAL("wrong group name",
686 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900687 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
688 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100689 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200690
691 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300692 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200693 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
694 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
695 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
696 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
697 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
698 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
699 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
700 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
701 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900702 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100703 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200704
705 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300706 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200707 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
708 TEST_ASSERT_VAL("wrong config",
709 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
710 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
711 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
712 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
713 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
714 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
715 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900716 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100717 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200718
719 return 0;
720}
721
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300722static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200723{
724 struct perf_evsel *evsel, *leader;
725
726 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900727 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200728
729 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300730 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200731 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
732 TEST_ASSERT_VAL("wrong config",
733 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
734 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
735 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
736 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200737 /* use of precise requires exclude_guest */
738 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200739 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
740 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
741 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900742 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900743 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
744 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
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 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300748 evsel = 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_INSTRUCTIONS == 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);
Jiri Olsa42be7392012-10-20 18:29:34 +0200755 /* use of precise requires exclude_guest */
756 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200757 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
758 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
759 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900760 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100761 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200762
763 return 0;
764}
765
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300766static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200767{
768 struct perf_evsel *evsel, *leader;
769
770 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900771 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200772
773 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300774 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200775 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
776 TEST_ASSERT_VAL("wrong config",
777 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
778 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
779 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
780 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
781 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
782 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
783 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
784 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900785 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900786 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
787 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100788 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200789
790 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300791 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200792 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
793 TEST_ASSERT_VAL("wrong config",
794 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
795 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
796 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
797 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
798 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
799 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
800 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
801 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900802 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100803 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200804
805 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300806 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200807 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
808 TEST_ASSERT_VAL("wrong config",
809 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
810 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
811 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
812 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
813 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
814 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
815 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
816 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900817 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900818 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
819 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100820 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200821
822 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300823 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200824 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
825 TEST_ASSERT_VAL("wrong config",
826 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
827 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
828 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
829 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
830 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
831 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
832 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
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 Olsa905f5ee2012-08-08 12:23:52 +0200835
836 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300837 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200838 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
839 TEST_ASSERT_VAL("wrong config",
840 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
841 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
842 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
843 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
844 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
845 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
846 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900847 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200848
849 return 0;
850}
851
Jiri Olsa5a30a992013-02-04 10:56:43 +0100852static int test__group_gh1(struct perf_evlist *evlist)
853{
854 struct perf_evsel *evsel, *leader;
855
856 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
857 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
858
859 /* cycles + :H group modifier */
860 evsel = leader = perf_evlist__first(evlist);
861 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
862 TEST_ASSERT_VAL("wrong config",
863 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
864 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
865 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
866 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
867 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
868 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
869 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
870 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
871 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
872 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
873 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
874
875 /* cache-misses:G + :H group modifier */
876 evsel = perf_evsel__next(evsel);
877 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
878 TEST_ASSERT_VAL("wrong config",
879 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
880 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
881 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
882 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
883 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
884 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
885 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
886 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
887 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
888
889 return 0;
890}
891
892static int test__group_gh2(struct perf_evlist *evlist)
893{
894 struct perf_evsel *evsel, *leader;
895
896 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
897 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
898
899 /* cycles + :G group modifier */
900 evsel = leader = perf_evlist__first(evlist);
901 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
902 TEST_ASSERT_VAL("wrong config",
903 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
904 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
905 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
906 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
907 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
908 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
909 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
910 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
911 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
912 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
913 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
914
915 /* cache-misses:H + :G group modifier */
916 evsel = perf_evsel__next(evsel);
917 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
918 TEST_ASSERT_VAL("wrong config",
919 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
920 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
921 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
922 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
923 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
924 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
925 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
926 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
927 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
928
929 return 0;
930}
931
932static int test__group_gh3(struct perf_evlist *evlist)
933{
934 struct perf_evsel *evsel, *leader;
935
936 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
937 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
938
939 /* cycles:G + :u group modifier */
940 evsel = leader = perf_evlist__first(evlist);
941 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
942 TEST_ASSERT_VAL("wrong config",
943 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
944 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
945 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
946 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
947 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
948 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
949 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
950 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
951 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
952 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
953 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
954
955 /* cache-misses:H + :u group modifier */
956 evsel = perf_evsel__next(evsel);
957 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
958 TEST_ASSERT_VAL("wrong config",
959 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
960 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
961 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
962 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
963 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
964 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
965 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
966 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
967 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
968
969 return 0;
970}
971
972static int test__group_gh4(struct perf_evlist *evlist)
973{
974 struct perf_evsel *evsel, *leader;
975
976 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
977 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
978
979 /* cycles:G + :uG group modifier */
980 evsel = leader = perf_evlist__first(evlist);
981 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
982 TEST_ASSERT_VAL("wrong config",
983 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
984 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
985 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
986 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
987 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
988 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
989 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
990 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
991 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
992 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
993 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
994
995 /* cache-misses:H + :uG group modifier */
996 evsel = perf_evsel__next(evsel);
997 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
998 TEST_ASSERT_VAL("wrong config",
999 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1000 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1001 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1002 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1003 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1004 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1005 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1006 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1007 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1008
1009 return 0;
1010}
1011
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001012static int test__leader_sample1(struct perf_evlist *evlist)
1013{
1014 struct perf_evsel *evsel, *leader;
1015
1016 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1017
1018 /* cycles - sampling group leader */
1019 evsel = leader = perf_evlist__first(evlist);
1020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1021 TEST_ASSERT_VAL("wrong config",
1022 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1023 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1024 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1025 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1026 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1027 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1028 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1029 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1030 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1031 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1032
1033 /* cache-misses - not sampling */
1034 evsel = perf_evsel__next(evsel);
1035 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1036 TEST_ASSERT_VAL("wrong config",
1037 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1038 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1039 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1040 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1041 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1042 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1043 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1044 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1045 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1046
1047 /* branch-misses - not sampling */
1048 evsel = perf_evsel__next(evsel);
1049 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1050 TEST_ASSERT_VAL("wrong config",
1051 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1052 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1053 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1054 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1055 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1056 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1057 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1058 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1059 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1060 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1061
1062 return 0;
1063}
1064
1065static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1066{
1067 struct perf_evsel *evsel, *leader;
1068
1069 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1070
1071 /* instructions - sampling group leader */
1072 evsel = leader = perf_evlist__first(evlist);
1073 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1074 TEST_ASSERT_VAL("wrong config",
1075 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1076 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1077 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1078 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1079 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1080 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1081 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1082 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1083 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1084 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1085
1086 /* branch-misses - not sampling */
1087 evsel = perf_evsel__next(evsel);
1088 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1089 TEST_ASSERT_VAL("wrong config",
1090 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1091 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1092 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1093 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1094 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1095 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1096 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1097 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1098 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1099 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1100
1101 return 0;
1102}
1103
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001104static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1105{
1106 struct perf_evsel *evsel = perf_evlist__first(evlist);
1107
1108 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1109 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1110 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1111 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
1112 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1113
1114 return test__checkevent_symbolic_name(evlist);
1115}
1116
1117static int test__pinned_group(struct perf_evlist *evlist)
1118{
1119 struct perf_evsel *evsel, *leader;
1120
1121 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1122
1123 /* cycles - group leader */
1124 evsel = leader = perf_evlist__first(evlist);
1125 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1126 TEST_ASSERT_VAL("wrong config",
1127 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1128 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1129 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1130 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1131
1132 /* cache-misses - can not be pinned, but will go on with the leader */
1133 evsel = perf_evsel__next(evsel);
1134 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1135 TEST_ASSERT_VAL("wrong config",
1136 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1137 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1138
1139 /* branch-misses - ditto */
1140 evsel = perf_evsel__next(evsel);
1141 TEST_ASSERT_VAL("wrong config",
1142 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1143 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1144
1145 return 0;
1146}
1147
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001148static int count_tracepoints(void)
1149{
1150 char events_path[PATH_MAX];
1151 struct dirent *events_ent;
1152 DIR *events_dir;
1153 int cnt = 0;
1154
1155 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1156 debugfs_find_mountpoint());
1157
1158 events_dir = opendir(events_path);
1159
1160 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1161
1162 while ((events_ent = readdir(events_dir))) {
1163 char sys_path[PATH_MAX];
1164 struct dirent *sys_ent;
1165 DIR *sys_dir;
1166
1167 if (!strcmp(events_ent->d_name, ".")
1168 || !strcmp(events_ent->d_name, "..")
1169 || !strcmp(events_ent->d_name, "enable")
1170 || !strcmp(events_ent->d_name, "header_event")
1171 || !strcmp(events_ent->d_name, "header_page"))
1172 continue;
1173
1174 scnprintf(sys_path, PATH_MAX, "%s/%s",
1175 events_path, events_ent->d_name);
1176
1177 sys_dir = opendir(sys_path);
1178 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1179
1180 while ((sys_ent = readdir(sys_dir))) {
1181 if (!strcmp(sys_ent->d_name, ".")
1182 || !strcmp(sys_ent->d_name, "..")
1183 || !strcmp(sys_ent->d_name, "enable")
1184 || !strcmp(sys_ent->d_name, "filter"))
1185 continue;
1186
1187 cnt++;
1188 }
1189
1190 closedir(sys_dir);
1191 }
1192
1193 closedir(events_dir);
1194 return cnt;
1195}
1196
1197static int test__all_tracepoints(struct perf_evlist *evlist)
1198{
1199 TEST_ASSERT_VAL("wrong events count",
1200 count_tracepoints() == evlist->nr_entries);
1201
1202 return test__checkevent_tracepoint_multi(evlist);
1203}
1204
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001205struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001206 const char *name;
1207 __u32 type;
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001208 const int id;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001209 int (*check)(struct perf_evlist *evlist);
1210};
1211
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001212static struct evlist_test test__events[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001213 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001214 .name = "syscalls:sys_enter_open",
1215 .check = test__checkevent_tracepoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001216 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001217 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001218 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001219 .name = "syscalls:*",
1220 .check = test__checkevent_tracepoint_multi,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001221 .id = 1,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001222 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001223 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001224 .name = "r1a",
1225 .check = test__checkevent_raw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001226 .id = 2,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001227 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001228 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001229 .name = "1:1",
1230 .check = test__checkevent_numeric,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001231 .id = 3,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001232 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001233 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001234 .name = "instructions",
1235 .check = test__checkevent_symbolic_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001236 .id = 4,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001237 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001238 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001239 .name = "cycles/period=100000,config2/",
1240 .check = test__checkevent_symbolic_name_config,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001241 .id = 5,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001242 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001243 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001244 .name = "faults",
1245 .check = test__checkevent_symbolic_alias,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001246 .id = 6,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001247 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001248 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001249 .name = "L1-dcache-load-miss",
1250 .check = test__checkevent_genhw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001251 .id = 7,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001252 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001253 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001254 .name = "mem:0",
1255 .check = test__checkevent_breakpoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001256 .id = 8,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001257 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001258 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001259 .name = "mem:0:x",
1260 .check = test__checkevent_breakpoint_x,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001261 .id = 9,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001262 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001263 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001264 .name = "mem:0:r",
1265 .check = test__checkevent_breakpoint_r,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001266 .id = 10,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001267 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001268 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001269 .name = "mem:0:w",
1270 .check = test__checkevent_breakpoint_w,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001271 .id = 11,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001272 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001273 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001274 .name = "syscalls:sys_enter_open:k",
1275 .check = test__checkevent_tracepoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001276 .id = 12,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001277 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001278 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001279 .name = "syscalls:*:u",
1280 .check = test__checkevent_tracepoint_multi_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001281 .id = 13,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001282 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001283 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001284 .name = "r1a:kp",
1285 .check = test__checkevent_raw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001286 .id = 14,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001287 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001288 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001289 .name = "1:1:hp",
1290 .check = test__checkevent_numeric_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001291 .id = 15,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001292 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001293 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001294 .name = "instructions:h",
1295 .check = test__checkevent_symbolic_name_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001296 .id = 16,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001297 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001298 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001299 .name = "faults:u",
1300 .check = test__checkevent_symbolic_alias_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001301 .id = 17,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001302 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001303 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001304 .name = "L1-dcache-load-miss:kp",
1305 .check = test__checkevent_genhw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001306 .id = 18,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001307 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001308 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001309 .name = "mem:0:u",
1310 .check = test__checkevent_breakpoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001311 .id = 19,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001312 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001313 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001314 .name = "mem:0:x:k",
1315 .check = test__checkevent_breakpoint_x_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001316 .id = 20,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001317 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001318 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001319 .name = "mem:0:r:hp",
1320 .check = test__checkevent_breakpoint_r_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001321 .id = 21,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001322 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001323 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001324 .name = "mem:0:w:up",
1325 .check = test__checkevent_breakpoint_w_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001326 .id = 22,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001327 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001328 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001329 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
1330 .check = test__checkevent_list,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001331 .id = 23,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001332 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001333 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001334 .name = "instructions:G",
1335 .check = test__checkevent_exclude_host_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001336 .id = 24,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001337 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001338 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001339 .name = "instructions:H",
1340 .check = test__checkevent_exclude_guest_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001341 .id = 25,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001342 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001343 {
Jiri Olsa75827322012-06-29 09:22:54 +02001344 .name = "mem:0:rw",
1345 .check = test__checkevent_breakpoint_rw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001346 .id = 26,
Jiri Olsa75827322012-06-29 09:22:54 +02001347 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001348 {
Jiri Olsa75827322012-06-29 09:22:54 +02001349 .name = "mem:0:rw:kp",
1350 .check = test__checkevent_breakpoint_rw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001351 .id = 27,
Jiri Olsa75827322012-06-29 09:22:54 +02001352 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001353 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001354 .name = "{instructions:k,cycles:upp}",
1355 .check = test__group1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001356 .id = 28,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001357 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001358 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001359 .name = "{faults:k,cache-references}:u,cycles:k",
1360 .check = test__group2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001361 .id = 29,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001362 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001363 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001364 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1365 .check = test__group3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001366 .id = 30,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001367 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001368 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001369 .name = "{cycles:u,instructions:kp}:p",
1370 .check = test__group4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001371 .id = 31,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001372 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001373 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001374 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1375 .check = test__group5,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001376 .id = 32,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001377 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001378 {
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001379 .name = "*:*",
1380 .check = test__all_tracepoints,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001381 .id = 33,
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001382 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001383 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001384 .name = "{cycles,cache-misses:G}:H",
1385 .check = test__group_gh1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001386 .id = 34,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001387 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001388 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001389 .name = "{cycles,cache-misses:H}:G",
1390 .check = test__group_gh2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001391 .id = 35,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001392 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001393 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001394 .name = "{cycles:G,cache-misses:H}:u",
1395 .check = test__group_gh3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001396 .id = 36,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001397 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001398 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001399 .name = "{cycles:G,cache-misses:H}:uG",
1400 .check = test__group_gh4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001401 .id = 37,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001402 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001403 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001404 .name = "{cycles,cache-misses,branch-misses}:S",
1405 .check = test__leader_sample1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001406 .id = 38,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001407 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001408 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001409 .name = "{instructions,branch-misses}:Su",
1410 .check = test__leader_sample2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001411 .id = 39,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001412 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001413 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001414 .name = "instructions:uDp",
1415 .check = test__checkevent_pinned_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001416 .id = 40,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001417 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001418 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001419 .name = "{cycles,cache-misses,branch-misses}:D",
1420 .check = test__pinned_group,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001421 .id = 41,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001422 },
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001423#if defined(__s390x__)
1424 {
1425 .name = "kvm-s390:kvm_s390_create_vm",
1426 .check = test__checkevent_tracepoint,
1427 .id = 100,
1428 },
1429#endif
Jiri Olsaf50246e2012-05-21 09:12:49 +02001430};
1431
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001432static struct evlist_test test__events_pmu[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001433 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001434 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1435 .check = test__checkevent_pmu,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001436 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001437 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001438 {
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001439 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1440 .check = test__checkevent_pmu_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001441 .id = 1,
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001442 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001443};
1444
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001445struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001446 const char *str;
1447 __u32 type;
1448 int (*check)(struct list_head *terms);
1449};
1450
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001451static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001452 [0] = {
1453 .str = "config=10,config1,config2=3,umask=1",
1454 .check = test__checkterms_simple,
1455 },
1456};
1457
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001458static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001459{
1460 struct perf_evlist *evlist;
1461 int ret;
1462
Namhyung Kim334fe7a2013-03-11 16:43:12 +09001463 evlist = perf_evlist__new();
Jiri Olsaf50246e2012-05-21 09:12:49 +02001464 if (evlist == NULL)
1465 return -ENOMEM;
1466
Jiri Olsad8f7bbc2013-01-15 14:39:51 +01001467 ret = parse_events(evlist, e->name);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001468 if (ret) {
1469 pr_debug("failed to parse event '%s', err %d\n",
1470 e->name, ret);
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001471 } else {
1472 ret = e->check(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001473 }
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001474
Jiri Olsaf50246e2012-05-21 09:12:49 +02001475 perf_evlist__delete(evlist);
1476
1477 return ret;
1478}
1479
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001480static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001481{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001482 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001483 unsigned i;
1484
1485 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001486 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001487
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001488 pr_debug("running test %d '%s'\n", e->id, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001489 ret1 = test_event(e);
1490 if (ret1)
1491 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001492 }
1493
Robert Richter9bfbbc62012-08-21 20:03:15 +02001494 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001495}
1496
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001497static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001498{
David Ahernc549aca2013-07-02 13:27:24 -06001499 struct list_head terms;
Jiri Olsa44293922012-06-15 14:31:42 +08001500 int ret;
1501
David Ahernc549aca2013-07-02 13:27:24 -06001502 INIT_LIST_HEAD(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001503
David Ahernc549aca2013-07-02 13:27:24 -06001504 ret = parse_events_terms(&terms, t->str);
Jiri Olsa44293922012-06-15 14:31:42 +08001505 if (ret) {
1506 pr_debug("failed to parse terms '%s', err %d\n",
1507 t->str , ret);
1508 return ret;
1509 }
1510
David Ahernc549aca2013-07-02 13:27:24 -06001511 ret = t->check(&terms);
1512 parse_events__free_terms(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001513
1514 return ret;
1515}
1516
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001517static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001518{
1519 int ret = 0;
1520 unsigned i;
1521
1522 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001523 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001524
1525 pr_debug("running test %d '%s'\n", i, t->str);
1526 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001527 if (ret)
1528 break;
1529 }
1530
1531 return ret;
1532}
1533
1534static int test_pmu(void)
1535{
1536 struct stat st;
1537 char path[PATH_MAX];
1538 int ret;
1539
1540 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001541 sysfs__mountpoint());
Jiri Olsaf50246e2012-05-21 09:12:49 +02001542
1543 ret = stat(path, &st);
1544 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001545 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001546 return !ret;
1547}
1548
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001549static int test_pmu_events(void)
1550{
1551 struct stat st;
1552 char path[PATH_MAX];
1553 struct dirent *ent;
1554 DIR *dir;
1555 int ret;
1556
1557 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001558 sysfs__mountpoint());
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001559
1560 ret = stat(path, &st);
1561 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001562 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001563 return 0;
1564 }
1565
1566 dir = opendir(path);
1567 if (!dir) {
1568 pr_debug("can't open pmu event dir");
1569 return -1;
1570 }
1571
1572 while (!ret && (ent = readdir(dir))) {
1573#define MAX_NAME 100
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001574 struct evlist_test e;
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001575 char name[MAX_NAME];
1576
1577 if (!strcmp(ent->d_name, ".") ||
1578 !strcmp(ent->d_name, ".."))
1579 continue;
1580
1581 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1582
1583 e.name = name;
1584 e.check = test__checkevent_pmu_events;
1585
1586 ret = test_event(&e);
Kan Liangffe59782014-10-07 11:08:52 -04001587 if (ret)
1588 break;
1589 snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1590 e.name = name;
1591 e.check = test__checkevent_pmu_events_mix;
1592 ret = test_event(&e);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001593#undef MAX_NAME
1594 }
1595
1596 closedir(dir);
1597 return ret;
1598}
1599
Jiri Olsac81251e2012-11-10 01:46:51 +01001600int test__parse_events(void)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001601{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001602 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001603
Jiri Olsaebf124f2012-07-04 00:00:47 +02001604#define TEST_EVENTS(tests) \
1605do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001606 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1607 if (!ret2) \
1608 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001609} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001610
Jiri Olsaebf124f2012-07-04 00:00:47 +02001611 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001612
Jiri Olsaebf124f2012-07-04 00:00:47 +02001613 if (test_pmu())
1614 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001615
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001616 if (test_pmu()) {
1617 int ret = test_pmu_events();
1618 if (ret)
1619 return ret;
1620 }
1621
Robert Richter9bfbbc62012-08-21 20:03:15 +02001622 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1623 if (!ret2)
1624 ret2 = ret1;
1625
1626 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001627}