blob: f0679613bd1878210163308426cd67f0b8ab181a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jiri Olsaf50246e2012-05-21 09:12:49 +02002#include "parse-events.h"
3#include "evsel.h"
4#include "evlist.h"
Borislav Petkovcd0cfad2013-12-09 17:14:24 +01005#include <api/fs/fs.h>
Jiri Olsac81251e2012-11-10 01:46:51 +01006#include "tests.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02007#include "debug.h"
Namhyung Kim2690c732015-10-20 00:23:49 +09008#include "util.h"
Arnaldo Carvalho de Melo76b31a22017-04-18 12:26:44 -03009#include <dirent.h>
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -030010#include <errno.h>
Arnaldo Carvalho de Melo7a8ef4c2017-04-19 20:57:47 -030011#include <sys/types.h>
12#include <sys/stat.h>
13#include <unistd.h>
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -030014#include <linux/kernel.h>
David Howellsd2709c72012-11-19 22:21:03 +000015#include <linux/hw_breakpoint.h>
Jiri Olsa4605eab2015-09-02 09:56:43 +020016#include <api/fs/fs.h>
Arnaldo Carvalho de Melo20a9ed22017-04-18 11:44:58 -030017#include <api/fs/tracing_path.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +020018
Jiri Olsa30f31c02012-08-01 14:48:58 +020019#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
20 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
21
Jiri Olsaf50246e2012-05-21 09:12:49 +020022static int test__checkevent_tracepoint(struct perf_evlist *evlist)
23{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030024 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020025
26 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090027 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020028 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
29 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020030 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020031 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
32 return 0;
33}
34
35static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
36{
37 struct perf_evsel *evsel;
38
39 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090040 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020041
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030042 evlist__for_each_entry(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +020043 TEST_ASSERT_VAL("wrong type",
44 PERF_TYPE_TRACEPOINT == evsel->attr.type);
45 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020046 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020047 TEST_ASSERT_VAL("wrong sample_period",
48 1 == evsel->attr.sample_period);
49 }
50 return 0;
51}
52
53static int test__checkevent_raw(struct perf_evlist *evlist)
54{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030055 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020056
57 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
58 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
59 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
60 return 0;
61}
62
63static int test__checkevent_numeric(struct perf_evlist *evlist)
64{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030065 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020066
67 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
68 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
69 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
70 return 0;
71}
72
73static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
74{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030075 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020076
77 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
78 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
79 TEST_ASSERT_VAL("wrong config",
80 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
81 return 0;
82}
83
84static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
85{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030086 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020087
88 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
89 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
90 TEST_ASSERT_VAL("wrong config",
91 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
Jiri Olsaee4c7582015-07-29 05:42:11 -040092 /*
93 * The period value gets configured within perf_evlist__config,
94 * while this test executes only parse events method.
95 */
Jiri Olsaf50246e2012-05-21 09:12:49 +020096 TEST_ASSERT_VAL("wrong period",
Jiri Olsaee4c7582015-07-29 05:42:11 -040097 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +020098 TEST_ASSERT_VAL("wrong config1",
99 0 == evsel->attr.config1);
100 TEST_ASSERT_VAL("wrong config2",
101 1 == evsel->attr.config2);
102 return 0;
103}
104
105static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
106{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300107 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200108
109 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
110 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
111 TEST_ASSERT_VAL("wrong config",
112 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
113 return 0;
114}
115
116static int test__checkevent_genhw(struct perf_evlist *evlist)
117{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300118 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200119
120 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
121 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
122 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
123 return 0;
124}
125
126static int test__checkevent_breakpoint(struct perf_evlist *evlist)
127{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300128 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200129
130 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
131 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
132 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
133 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
134 evsel->attr.bp_type);
135 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
136 evsel->attr.bp_len);
137 return 0;
138}
139
140static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
141{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300142 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200143
144 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
145 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
146 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
147 TEST_ASSERT_VAL("wrong bp_type",
148 HW_BREAKPOINT_X == evsel->attr.bp_type);
149 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
150 return 0;
151}
152
153static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
154{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300155 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200156
157 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
158 TEST_ASSERT_VAL("wrong type",
159 PERF_TYPE_BREAKPOINT == evsel->attr.type);
160 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
161 TEST_ASSERT_VAL("wrong bp_type",
162 HW_BREAKPOINT_R == evsel->attr.bp_type);
163 TEST_ASSERT_VAL("wrong bp_len",
164 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
165 return 0;
166}
167
168static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
169{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300170 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200171
172 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
173 TEST_ASSERT_VAL("wrong type",
174 PERF_TYPE_BREAKPOINT == evsel->attr.type);
175 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
176 TEST_ASSERT_VAL("wrong bp_type",
177 HW_BREAKPOINT_W == evsel->attr.bp_type);
178 TEST_ASSERT_VAL("wrong bp_len",
179 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
180 return 0;
181}
182
Jiri Olsa75827322012-06-29 09:22:54 +0200183static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
184{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300185 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200186
187 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
188 TEST_ASSERT_VAL("wrong type",
189 PERF_TYPE_BREAKPOINT == evsel->attr.type);
190 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
191 TEST_ASSERT_VAL("wrong bp_type",
192 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
193 TEST_ASSERT_VAL("wrong bp_len",
194 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
195 return 0;
196}
197
Jiri Olsaf50246e2012-05-21 09:12:49 +0200198static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
199{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300200 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200201
202 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
203 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
204 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
205 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
206
207 return test__checkevent_tracepoint(evlist);
208}
209
210static int
211test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
212{
213 struct perf_evsel *evsel;
214
215 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
216
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300217 evlist__for_each_entry(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200218 TEST_ASSERT_VAL("wrong exclude_user",
219 !evsel->attr.exclude_user);
220 TEST_ASSERT_VAL("wrong exclude_kernel",
221 evsel->attr.exclude_kernel);
222 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
223 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
224 }
225
226 return test__checkevent_tracepoint_multi(evlist);
227}
228
229static int test__checkevent_raw_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_raw(evlist);
239}
240
241static int test__checkevent_numeric_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_numeric(evlist);
251}
252
253static int test__checkevent_symbolic_name_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_user", evsel->attr.exclude_user);
258 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
259 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
260 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
261
262 return test__checkevent_symbolic_name(evlist);
263}
264
265static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
266{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300267 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200268
269 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
270 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
271
272 return test__checkevent_symbolic_name(evlist);
273}
274
275static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
276{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300277 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200278
279 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
280 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
281
282 return test__checkevent_symbolic_name(evlist);
283}
284
285static int test__checkevent_symbolic_alias_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_symbolic_alias(evlist);
295}
296
297static int test__checkevent_genhw_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
301 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
302 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
303 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
304 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
305
306 return test__checkevent_genhw(evlist);
307}
308
Jiri Olsaa1e12da2015-04-07 23:25:14 +0200309static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist)
310{
311 struct perf_evsel *evsel = perf_evlist__first(evlist);
312
313 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
314 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
315 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
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);
320
321 return test__checkevent_symbolic_name(evlist);
322}
323
324static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist)
325{
326 struct perf_evsel *evsel = perf_evlist__first(evlist);
327
328 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
329 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
330 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
331 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
332 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
333 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
334 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
335
336 return test__checkevent_symbolic_name(evlist);
337}
338
Jiri Olsaf50246e2012-05-21 09:12:49 +0200339static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
340{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300341 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200342
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:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200350
351 return test__checkevent_breakpoint(evlist);
352}
353
354static int test__checkevent_breakpoint_x_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 Olsaf50246e2012-05-21 09:12:49 +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:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200364
365 return test__checkevent_breakpoint_x(evlist);
366}
367
368static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
369{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300370 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200371
372 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
373 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
374 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
375 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200376 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200377 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200378
379 return test__checkevent_breakpoint_r(evlist);
380}
381
382static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
383{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300384 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200385
386 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
387 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
388 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
389 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200390 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200391 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200392
393 return test__checkevent_breakpoint_w(evlist);
394}
395
Jiri Olsa75827322012-06-29 09:22:54 +0200396static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
397{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300398 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200399
400 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
401 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
402 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
403 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200404 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200405 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200406
407 return test__checkevent_breakpoint_rw(evlist);
408}
409
Jiri Olsaf50246e2012-05-21 09:12:49 +0200410static int test__checkevent_pmu(struct perf_evlist *evlist)
411{
412
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300413 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200414
415 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
416 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
417 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
418 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
419 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
Jiri Olsaee4c7582015-07-29 05:42:11 -0400420 /*
421 * The period value gets configured within perf_evlist__config,
422 * while this test executes only parse events method.
423 */
424 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200425
426 return 0;
427}
428
429static int test__checkevent_list(struct perf_evlist *evlist)
430{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300431 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200432
433 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
434
435 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200436 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
437 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
438 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
439 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
440 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
441 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
442 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
443 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
444
Riku Voipio43f322b2015-04-16 16:52:53 +0300445 /* syscalls:sys_enter_openat:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300446 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200447 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
448 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200449 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200450 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
451 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
452 TEST_ASSERT_VAL("wrong exclude_kernel", !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);
455
456 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300457 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200458 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
459 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
460 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
461 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
462 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
463 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
464
465 return 0;
466}
467
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200468static int test__checkevent_pmu_name(struct perf_evlist *evlist)
469{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300470 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200471
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200472 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200473 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
474 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
475 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300476 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200477
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200478 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300479 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200480 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
481 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
482 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200483 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200484 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200485
486 return 0;
487}
488
Kan Liang71ef1502015-08-11 06:30:50 -0400489static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist)
490{
491 struct perf_evsel *evsel = perf_evlist__first(evlist);
492
493 /* cpu/config=1,call-graph=fp,time,period=100000/ */
494 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
495 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
496 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
497 /*
498 * The period, time and callgraph value gets configured
499 * within perf_evlist__config,
500 * while this test executes only parse events method.
501 */
502 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
503 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
504 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
505
506 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
507 evsel = perf_evsel__next(evsel);
508 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
509 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
510 /*
511 * The period, time and callgraph value gets configured
512 * within perf_evlist__config,
513 * while this test executes only parse events method.
514 */
515 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
516 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
517 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
518
519 return 0;
520}
521
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200522static int test__checkevent_pmu_events(struct perf_evlist *evlist)
523{
Arnaldo Carvalho de Melo9a354cd2013-11-13 15:54:30 -0300524 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200525
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200526 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
527 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
528 TEST_ASSERT_VAL("wrong exclude_user",
529 !evsel->attr.exclude_user);
530 TEST_ASSERT_VAL("wrong exclude_kernel",
531 evsel->attr.exclude_kernel);
532 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
533 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Michael Ellermanc9ee7802013-08-06 23:28:06 +1000534 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200535
536 return 0;
537}
538
Kan Liangffe59782014-10-07 11:08:52 -0400539
540static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
541{
542 struct perf_evsel *evsel = perf_evlist__first(evlist);
543
544 /* pmu-event:u */
545 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
546 TEST_ASSERT_VAL("wrong exclude_user",
547 !evsel->attr.exclude_user);
548 TEST_ASSERT_VAL("wrong exclude_kernel",
549 evsel->attr.exclude_kernel);
550 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
551 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
552 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
553
554 /* cpu/pmu-event/u*/
555 evsel = perf_evsel__next(evsel);
556 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
557 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
558 TEST_ASSERT_VAL("wrong exclude_user",
559 !evsel->attr.exclude_user);
560 TEST_ASSERT_VAL("wrong exclude_kernel",
561 evsel->attr.exclude_kernel);
562 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
563 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
564 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
565
566 return 0;
567}
568
Jiri Olsa44293922012-06-15 14:31:42 +0800569static int test__checkterms_simple(struct list_head *terms)
570{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300571 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800572
573 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300574 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800575 TEST_ASSERT_VAL("wrong type term",
576 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
577 TEST_ASSERT_VAL("wrong type val",
578 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
579 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
580 TEST_ASSERT_VAL("wrong config", !term->config);
581
582 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300583 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800584 TEST_ASSERT_VAL("wrong type term",
585 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
586 TEST_ASSERT_VAL("wrong type val",
587 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
588 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
589 TEST_ASSERT_VAL("wrong config", !term->config);
590
591 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300592 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800593 TEST_ASSERT_VAL("wrong type term",
594 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
595 TEST_ASSERT_VAL("wrong type val",
596 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
597 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
598 TEST_ASSERT_VAL("wrong config", !term->config);
599
600 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300601 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800602 TEST_ASSERT_VAL("wrong type term",
603 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
604 TEST_ASSERT_VAL("wrong type val",
605 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
606 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
607 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
608
609 return 0;
610}
611
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200612static int test__group1(struct perf_evlist *evlist)
613{
614 struct perf_evsel *evsel, *leader;
615
616 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900617 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200618
619 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300620 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200621 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
622 TEST_ASSERT_VAL("wrong config",
623 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
624 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
625 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
626 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
627 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
628 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
629 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900630 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900631 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
632 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100633 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200634
635 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300636 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200637 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
638 TEST_ASSERT_VAL("wrong config",
639 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
640 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
641 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
642 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200643 /* use of precise requires exclude_guest */
644 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200645 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
646 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
647 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900648 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100649 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200650
651 return 0;
652}
653
654static int test__group2(struct perf_evlist *evlist)
655{
656 struct perf_evsel *evsel, *leader;
657
658 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900659 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200660
661 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300662 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200663 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
664 TEST_ASSERT_VAL("wrong config",
665 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
666 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
667 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
668 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
669 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
670 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
671 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900672 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900673 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
674 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100675 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200676
677 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300678 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200679 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
680 TEST_ASSERT_VAL("wrong config",
681 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
682 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
683 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
684 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100685 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200686 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
687 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
688 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900689 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100690 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200691
692 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300693 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200694 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
695 TEST_ASSERT_VAL("wrong config",
696 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
697 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
698 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
699 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
700 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
701 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
702 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900703 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100704 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200705
706 return 0;
707}
708
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300709static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200710{
711 struct perf_evsel *evsel, *leader;
712
713 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900714 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200715
Riku Voipio43f322b2015-04-16 16:52:53 +0300716 /* group1 syscalls:sys_enter_openat:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300717 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200718 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
719 TEST_ASSERT_VAL("wrong sample_type",
720 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
721 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
722 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
723 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
724 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
725 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
726 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
727 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900728 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200729 TEST_ASSERT_VAL("wrong group name",
730 !strcmp(leader->group_name, "group1"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900731 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
732 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100733 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200734
735 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300736 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200737 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
738 TEST_ASSERT_VAL("wrong config",
739 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
740 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
741 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
742 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200743 /* use of precise requires exclude_guest */
744 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200745 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
746 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
747 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
748 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900749 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100750 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200751
752 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300753 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200754 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
755 TEST_ASSERT_VAL("wrong config",
756 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
757 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
758 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
759 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
760 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
761 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
762 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900763 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200764 TEST_ASSERT_VAL("wrong group name",
765 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900766 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
767 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100768 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200769
770 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300771 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200772 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
773 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
774 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
775 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
776 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
777 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
778 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
779 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
780 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900781 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100782 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200783
784 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300785 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200786 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
787 TEST_ASSERT_VAL("wrong config",
788 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
789 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
790 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
791 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
792 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
793 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
794 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900795 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100796 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200797
798 return 0;
799}
800
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300801static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200802{
803 struct perf_evsel *evsel, *leader;
804
805 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900806 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200807
808 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300809 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200810 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
811 TEST_ASSERT_VAL("wrong config",
812 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
813 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
814 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
815 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200816 /* use of precise requires exclude_guest */
817 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200818 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
819 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
820 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900821 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900822 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
823 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100824 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200825
826 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300827 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200828 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
829 TEST_ASSERT_VAL("wrong config",
830 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
831 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
832 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
833 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200834 /* use of precise requires exclude_guest */
835 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200836 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
837 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
838 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900839 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100840 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200841
842 return 0;
843}
844
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300845static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200846{
847 struct perf_evsel *evsel, *leader;
848
849 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900850 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200851
852 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300853 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200854 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
855 TEST_ASSERT_VAL("wrong config",
856 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
857 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
858 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
859 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
860 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
861 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
862 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
863 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900864 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900865 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
866 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100867 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200868
869 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300870 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200871 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
872 TEST_ASSERT_VAL("wrong config",
873 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
874 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
875 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
876 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
877 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
878 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
879 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
880 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900881 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100882 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200883
884 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300885 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200886 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
887 TEST_ASSERT_VAL("wrong config",
888 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
889 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
890 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
891 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
892 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
893 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
894 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
895 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900896 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900897 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
898 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100899 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200900
901 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300902 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200903 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
904 TEST_ASSERT_VAL("wrong config",
905 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
906 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
907 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
908 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
909 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
910 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
911 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
912 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900913 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200914
915 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300916 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200917 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
918 TEST_ASSERT_VAL("wrong config",
919 PERF_COUNT_HW_CPU_CYCLES == 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);
Namhyung Kim823254e2012-11-29 15:38:30 +0900926 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200927
928 return 0;
929}
930
Jiri Olsa5a30a992013-02-04 10:56:43 +0100931static int test__group_gh1(struct perf_evlist *evlist)
932{
933 struct perf_evsel *evsel, *leader;
934
935 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
936 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
937
938 /* cycles + :H group modifier */
939 evsel = leader = perf_evlist__first(evlist);
940 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
941 TEST_ASSERT_VAL("wrong config",
942 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
943 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
944 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
945 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
946 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
947 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
948 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
949 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
950 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
951 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
952 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
953
954 /* cache-misses:G + :H group modifier */
955 evsel = perf_evsel__next(evsel);
956 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
957 TEST_ASSERT_VAL("wrong config",
958 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
959 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
960 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
961 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
962 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
963 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
964 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
965 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
966 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
967
968 return 0;
969}
970
971static int test__group_gh2(struct perf_evlist *evlist)
972{
973 struct perf_evsel *evsel, *leader;
974
975 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
976 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
977
978 /* cycles + :G group modifier */
979 evsel = leader = perf_evlist__first(evlist);
980 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
981 TEST_ASSERT_VAL("wrong config",
982 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
983 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
984 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
985 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
986 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
987 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
988 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
989 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
990 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
991 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
992 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
993
994 /* cache-misses:H + :G group modifier */
995 evsel = perf_evsel__next(evsel);
996 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
997 TEST_ASSERT_VAL("wrong config",
998 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
999 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1000 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1001 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1002 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1003 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1004 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1005 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1006 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1007
1008 return 0;
1009}
1010
1011static int test__group_gh3(struct perf_evlist *evlist)
1012{
1013 struct perf_evsel *evsel, *leader;
1014
1015 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1016 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1017
1018 /* cycles:G + :u group modifier */
1019 evsel = leader = perf_evlist__first(evlist);
1020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1021 TEST_ASSERT_VAL("wrong config",
1022 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1023 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1024 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1025 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1026 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1027 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1028 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1029 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1030 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1031 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1032 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1033
1034 /* cache-misses:H + :u group modifier */
1035 evsel = perf_evsel__next(evsel);
1036 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1037 TEST_ASSERT_VAL("wrong config",
1038 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1039 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1040 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1041 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1042 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1043 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1044 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1045 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1046 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1047
1048 return 0;
1049}
1050
1051static int test__group_gh4(struct perf_evlist *evlist)
1052{
1053 struct perf_evsel *evsel, *leader;
1054
1055 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1056 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1057
1058 /* cycles:G + :uG group modifier */
1059 evsel = leader = perf_evlist__first(evlist);
1060 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1061 TEST_ASSERT_VAL("wrong config",
1062 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1063 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1064 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1065 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1066 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1067 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1068 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1069 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1070 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1071 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1072 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1073
1074 /* cache-misses:H + :uG group modifier */
1075 evsel = perf_evsel__next(evsel);
1076 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1077 TEST_ASSERT_VAL("wrong config",
1078 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1079 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1080 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1081 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1082 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1083 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1084 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1085 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1086 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1087
1088 return 0;
1089}
1090
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001091static int test__leader_sample1(struct perf_evlist *evlist)
1092{
1093 struct perf_evsel *evsel, *leader;
1094
1095 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1096
1097 /* cycles - sampling group leader */
1098 evsel = leader = perf_evlist__first(evlist);
1099 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1100 TEST_ASSERT_VAL("wrong config",
1101 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1102 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1103 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1104 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1105 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1106 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1107 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1108 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1109 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1110 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1111
1112 /* cache-misses - not sampling */
1113 evsel = perf_evsel__next(evsel);
1114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1115 TEST_ASSERT_VAL("wrong config",
1116 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1117 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1118 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1119 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1120 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1121 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1122 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1123 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1124 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1125
1126 /* branch-misses - not sampling */
1127 evsel = perf_evsel__next(evsel);
1128 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1129 TEST_ASSERT_VAL("wrong config",
1130 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1131 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1132 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1133 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1134 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1135 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1136 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1137 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1138 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1139 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1140
1141 return 0;
1142}
1143
1144static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1145{
1146 struct perf_evsel *evsel, *leader;
1147
1148 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1149
1150 /* instructions - sampling group leader */
1151 evsel = leader = perf_evlist__first(evlist);
1152 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1153 TEST_ASSERT_VAL("wrong config",
1154 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1155 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1156 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1157 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1158 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1159 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1160 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1161 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1162 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1163 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1164
1165 /* branch-misses - not sampling */
1166 evsel = perf_evsel__next(evsel);
1167 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1168 TEST_ASSERT_VAL("wrong config",
1169 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1170 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1171 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1172 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1173 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1174 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1175 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1176 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1177 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1178 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1179
1180 return 0;
1181}
1182
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001183static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1184{
1185 struct perf_evsel *evsel = perf_evlist__first(evlist);
1186
1187 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1188 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1189 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1190 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
1191 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1192
1193 return test__checkevent_symbolic_name(evlist);
1194}
1195
1196static int test__pinned_group(struct perf_evlist *evlist)
1197{
1198 struct perf_evsel *evsel, *leader;
1199
1200 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1201
1202 /* cycles - group leader */
1203 evsel = leader = perf_evlist__first(evlist);
1204 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1205 TEST_ASSERT_VAL("wrong config",
1206 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1207 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1208 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1209 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1210
1211 /* cache-misses - can not be pinned, but will go on with the leader */
1212 evsel = perf_evsel__next(evsel);
1213 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1214 TEST_ASSERT_VAL("wrong config",
1215 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1216 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1217
1218 /* branch-misses - ditto */
1219 evsel = perf_evsel__next(evsel);
1220 TEST_ASSERT_VAL("wrong config",
1221 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1222 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1223
1224 return 0;
1225}
1226
Jacob Shinec323982014-05-29 17:26:52 +02001227static int test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1228{
1229 struct perf_evsel *evsel = perf_evlist__first(evlist);
1230
1231 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1232 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1233 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1234 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1235 evsel->attr.bp_type);
1236 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1237 evsel->attr.bp_len);
1238
1239 return 0;
1240}
1241
1242static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1243{
1244 struct perf_evsel *evsel = perf_evlist__first(evlist);
1245
1246 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1247 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1248 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1249 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1250 evsel->attr.bp_type);
1251 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1252 evsel->attr.bp_len);
1253
1254 return 0;
1255}
1256
1257static int
1258test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1259{
1260 struct perf_evsel *evsel = perf_evlist__first(evlist);
1261
1262 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1263 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1264 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1265 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1266
1267 return test__checkevent_breakpoint_rw(evlist);
1268}
1269
Jiri Olsaddd83c92015-10-05 20:06:06 +02001270static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
1271{
1272 struct perf_evsel *evsel = perf_evlist__first(evlist);
1273
1274 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1275 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
1276 TEST_ASSERT_VAL("wrong config",
1277 PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config);
1278 return 0;
1279}
1280
Wang Nan10bf3582016-02-19 11:44:00 +00001281static int test__checkevent_config_symbol(struct perf_evlist *evlist)
1282{
1283 struct perf_evsel *evsel = perf_evlist__first(evlist);
1284
1285 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1286 return 0;
1287}
1288
1289static int test__checkevent_config_raw(struct perf_evlist *evlist)
1290{
1291 struct perf_evsel *evsel = perf_evlist__first(evlist);
1292
1293 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1294 return 0;
1295}
1296
1297static int test__checkevent_config_num(struct perf_evlist *evlist)
1298{
1299 struct perf_evsel *evsel = perf_evlist__first(evlist);
1300
1301 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1302 return 0;
1303}
1304
Wang Nan43d0b972016-02-19 11:44:01 +00001305static int test__checkevent_config_cache(struct perf_evlist *evlist)
1306{
1307 struct perf_evsel *evsel = perf_evlist__first(evlist);
1308
1309 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1310 return 0;
1311}
Wang Nan10bf3582016-02-19 11:44:00 +00001312
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001313static int count_tracepoints(void)
1314{
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001315 struct dirent *events_ent;
1316 DIR *events_dir;
1317 int cnt = 0;
1318
Jiri Olsafbf99622015-09-02 09:56:45 +02001319 events_dir = opendir(tracing_events_path);
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001320
1321 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1322
1323 while ((events_ent = readdir(events_dir))) {
1324 char sys_path[PATH_MAX];
1325 struct dirent *sys_ent;
1326 DIR *sys_dir;
1327
1328 if (!strcmp(events_ent->d_name, ".")
1329 || !strcmp(events_ent->d_name, "..")
1330 || !strcmp(events_ent->d_name, "enable")
1331 || !strcmp(events_ent->d_name, "header_event")
1332 || !strcmp(events_ent->d_name, "header_page"))
1333 continue;
1334
1335 scnprintf(sys_path, PATH_MAX, "%s/%s",
Jiri Olsafbf99622015-09-02 09:56:45 +02001336 tracing_events_path, events_ent->d_name);
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001337
1338 sys_dir = opendir(sys_path);
1339 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1340
1341 while ((sys_ent = readdir(sys_dir))) {
1342 if (!strcmp(sys_ent->d_name, ".")
1343 || !strcmp(sys_ent->d_name, "..")
1344 || !strcmp(sys_ent->d_name, "enable")
1345 || !strcmp(sys_ent->d_name, "filter"))
1346 continue;
1347
1348 cnt++;
1349 }
1350
1351 closedir(sys_dir);
1352 }
1353
1354 closedir(events_dir);
1355 return cnt;
1356}
1357
1358static int test__all_tracepoints(struct perf_evlist *evlist)
1359{
1360 TEST_ASSERT_VAL("wrong events count",
1361 count_tracepoints() == evlist->nr_entries);
1362
1363 return test__checkevent_tracepoint_multi(evlist);
1364}
1365
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001366struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001367 const char *name;
1368 __u32 type;
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001369 const int id;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001370 int (*check)(struct perf_evlist *evlist);
1371};
1372
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001373static struct evlist_test test__events[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001374 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001375 .name = "syscalls:sys_enter_openat",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001376 .check = test__checkevent_tracepoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001377 .id = 0,
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 = "syscalls:*",
1381 .check = test__checkevent_tracepoint_multi,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001382 .id = 1,
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 = "r1a",
1386 .check = test__checkevent_raw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001387 .id = 2,
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 = "1:1",
1391 .check = test__checkevent_numeric,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001392 .id = 3,
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 = "instructions",
1396 .check = test__checkevent_symbolic_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001397 .id = 4,
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 = "cycles/period=100000,config2/",
1401 .check = test__checkevent_symbolic_name_config,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001402 .id = 5,
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 = "faults",
1406 .check = test__checkevent_symbolic_alias,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001407 .id = 6,
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 = "L1-dcache-load-miss",
1411 .check = test__checkevent_genhw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001412 .id = 7,
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",
1416 .check = test__checkevent_breakpoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001417 .id = 8,
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:x",
1421 .check = test__checkevent_breakpoint_x,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001422 .id = 9,
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:r",
1426 .check = test__checkevent_breakpoint_r,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001427 .id = 10,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001428 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001429 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001430 .name = "mem:0:w",
1431 .check = test__checkevent_breakpoint_w,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001432 .id = 11,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001433 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001434 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001435 .name = "syscalls:sys_enter_openat:k",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001436 .check = test__checkevent_tracepoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001437 .id = 12,
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 = "syscalls:*:u",
1441 .check = test__checkevent_tracepoint_multi_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001442 .id = 13,
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 = "r1a:kp",
1446 .check = test__checkevent_raw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001447 .id = 14,
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 = "1:1:hp",
1451 .check = test__checkevent_numeric_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001452 .id = 15,
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 = "instructions:h",
1456 .check = test__checkevent_symbolic_name_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001457 .id = 16,
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 = "faults:u",
1461 .check = test__checkevent_symbolic_alias_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001462 .id = 17,
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 = "L1-dcache-load-miss:kp",
1466 .check = test__checkevent_genhw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001467 .id = 18,
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:u",
1471 .check = test__checkevent_breakpoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001472 .id = 19,
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:x:k",
1476 .check = test__checkevent_breakpoint_x_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001477 .id = 20,
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:r:hp",
1481 .check = test__checkevent_breakpoint_r_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001482 .id = 21,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001483 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001484 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001485 .name = "mem:0:w:up",
1486 .check = test__checkevent_breakpoint_w_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001487 .id = 22,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001488 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001489 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001490 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001491 .check = test__checkevent_list,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001492 .id = 23,
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:G",
1496 .check = test__checkevent_exclude_host_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001497 .id = 24,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001498 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001499 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001500 .name = "instructions:H",
1501 .check = test__checkevent_exclude_guest_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001502 .id = 25,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001503 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001504 {
Jiri Olsa75827322012-06-29 09:22:54 +02001505 .name = "mem:0:rw",
1506 .check = test__checkevent_breakpoint_rw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001507 .id = 26,
Jiri Olsa75827322012-06-29 09:22:54 +02001508 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001509 {
Jiri Olsa75827322012-06-29 09:22:54 +02001510 .name = "mem:0:rw:kp",
1511 .check = test__checkevent_breakpoint_rw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001512 .id = 27,
Jiri Olsa75827322012-06-29 09:22:54 +02001513 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001514 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001515 .name = "{instructions:k,cycles:upp}",
1516 .check = test__group1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001517 .id = 28,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001518 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001519 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001520 .name = "{faults:k,cache-references}:u,cycles:k",
1521 .check = test__group2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001522 .id = 29,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001523 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001524 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001525 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001526 .check = test__group3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001527 .id = 30,
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:u,instructions:kp}:p",
1531 .check = test__group4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001532 .id = 31,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001533 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001534 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001535 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1536 .check = test__group5,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001537 .id = 32,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001538 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001539 {
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001540 .name = "*:*",
1541 .check = test__all_tracepoints,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001542 .id = 33,
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001543 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001544 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001545 .name = "{cycles,cache-misses:G}:H",
1546 .check = test__group_gh1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001547 .id = 34,
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,cache-misses:H}:G",
1551 .check = test__group_gh2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001552 .id = 35,
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}:u",
1556 .check = test__group_gh3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001557 .id = 36,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001558 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001559 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001560 .name = "{cycles:G,cache-misses:H}:uG",
1561 .check = test__group_gh4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001562 .id = 37,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001563 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001564 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001565 .name = "{cycles,cache-misses,branch-misses}:S",
1566 .check = test__leader_sample1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001567 .id = 38,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001568 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001569 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001570 .name = "{instructions,branch-misses}:Su",
1571 .check = test__leader_sample2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001572 .id = 39,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001573 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001574 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001575 .name = "instructions:uDp",
1576 .check = test__checkevent_pinned_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001577 .id = 40,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001578 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001579 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001580 .name = "{cycles,cache-misses,branch-misses}:D",
1581 .check = test__pinned_group,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001582 .id = 41,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001583 },
Jacob Shinec323982014-05-29 17:26:52 +02001584 {
1585 .name = "mem:0/1",
1586 .check = test__checkevent_breakpoint_len,
1587 .id = 42,
1588 },
1589 {
1590 .name = "mem:0/2:w",
1591 .check = test__checkevent_breakpoint_len_w,
1592 .id = 43,
1593 },
1594 {
1595 .name = "mem:0/4:rw:u",
1596 .check = test__checkevent_breakpoint_len_rw_modifier,
1597 .id = 44
1598 },
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001599#if defined(__s390x__)
1600 {
1601 .name = "kvm-s390:kvm_s390_create_vm",
1602 .check = test__checkevent_tracepoint,
1603 .id = 100,
1604 },
1605#endif
Jiri Olsaa1e12da2015-04-07 23:25:14 +02001606 {
1607 .name = "instructions:I",
1608 .check = test__checkevent_exclude_idle_modifier,
1609 .id = 45,
1610 },
1611 {
1612 .name = "instructions:kIG",
1613 .check = test__checkevent_exclude_idle_modifier_1,
1614 .id = 46,
1615 },
Jiri Olsaddd83c92015-10-05 20:06:06 +02001616 {
1617 .name = "task-clock:P,cycles",
1618 .check = test__checkevent_precise_max_modifier,
1619 .id = 47,
1620 },
Wang Nan10bf3582016-02-19 11:44:00 +00001621 {
1622 .name = "instructions/name=insn/",
1623 .check = test__checkevent_config_symbol,
1624 .id = 48,
1625 },
1626 {
1627 .name = "r1234/name=rawpmu/",
1628 .check = test__checkevent_config_raw,
1629 .id = 49,
1630 },
1631 {
1632 .name = "4:0x6530160/name=numpmu/",
1633 .check = test__checkevent_config_num,
1634 .id = 50,
1635 },
Wang Nan43d0b972016-02-19 11:44:01 +00001636 {
1637 .name = "L1-dcache-misses/name=cachepmu/",
1638 .check = test__checkevent_config_cache,
1639 .id = 51,
1640 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001641};
1642
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001643static struct evlist_test test__events_pmu[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001644 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001645 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1646 .check = test__checkevent_pmu,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001647 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001648 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001649 {
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001650 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1651 .check = test__checkevent_pmu_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001652 .id = 1,
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001653 },
Kan Liang71ef1502015-08-11 06:30:50 -04001654 {
1655 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1656 .check = test__checkevent_pmu_partial_time_callgraph,
1657 .id = 2,
1658 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001659};
1660
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001661struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001662 const char *str;
1663 __u32 type;
1664 int (*check)(struct list_head *terms);
1665};
1666
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001667static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001668 [0] = {
1669 .str = "config=10,config1,config2=3,umask=1",
1670 .check = test__checkterms_simple,
1671 },
1672};
1673
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001674static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001675{
1676 struct perf_evlist *evlist;
1677 int ret;
1678
Namhyung Kim334fe7a2013-03-11 16:43:12 +09001679 evlist = perf_evlist__new();
Jiri Olsaf50246e2012-05-21 09:12:49 +02001680 if (evlist == NULL)
1681 return -ENOMEM;
1682
Jiri Olsab39b8392015-04-22 21:10:16 +02001683 ret = parse_events(evlist, e->name, NULL);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001684 if (ret) {
1685 pr_debug("failed to parse event '%s', err %d\n",
1686 e->name, ret);
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001687 } else {
1688 ret = e->check(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001689 }
Arnaldo Carvalho de Melo48000a12014-12-17 17:24:45 -03001690
Jiri Olsaf50246e2012-05-21 09:12:49 +02001691 perf_evlist__delete(evlist);
1692
1693 return ret;
1694}
1695
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001696static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001697{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001698 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001699 unsigned i;
1700
1701 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001702 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001703
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001704 pr_debug("running test %d '%s'\n", e->id, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001705 ret1 = test_event(e);
1706 if (ret1)
1707 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001708 }
1709
Robert Richter9bfbbc62012-08-21 20:03:15 +02001710 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001711}
1712
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001713static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001714{
David Ahernc549aca2013-07-02 13:27:24 -06001715 struct list_head terms;
Jiri Olsa44293922012-06-15 14:31:42 +08001716 int ret;
1717
David Ahernc549aca2013-07-02 13:27:24 -06001718 INIT_LIST_HEAD(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001719
David Ahernc549aca2013-07-02 13:27:24 -06001720 ret = parse_events_terms(&terms, t->str);
Jiri Olsa44293922012-06-15 14:31:42 +08001721 if (ret) {
1722 pr_debug("failed to parse terms '%s', err %d\n",
1723 t->str , ret);
1724 return ret;
1725 }
1726
David Ahernc549aca2013-07-02 13:27:24 -06001727 ret = t->check(&terms);
Arnaldo Carvalho de Melo682dc242016-02-12 16:48:00 -03001728 parse_events_terms__purge(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001729
1730 return ret;
1731}
1732
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001733static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001734{
1735 int ret = 0;
1736 unsigned i;
1737
1738 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001739 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001740
1741 pr_debug("running test %d '%s'\n", i, t->str);
1742 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001743 if (ret)
1744 break;
1745 }
1746
1747 return ret;
1748}
1749
1750static int test_pmu(void)
1751{
1752 struct stat st;
1753 char path[PATH_MAX];
1754 int ret;
1755
1756 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001757 sysfs__mountpoint());
Jiri Olsaf50246e2012-05-21 09:12:49 +02001758
1759 ret = stat(path, &st);
1760 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001761 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001762 return !ret;
1763}
1764
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001765static int test_pmu_events(void)
1766{
1767 struct stat st;
1768 char path[PATH_MAX];
1769 struct dirent *ent;
1770 DIR *dir;
1771 int ret;
1772
1773 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001774 sysfs__mountpoint());
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001775
1776 ret = stat(path, &st);
1777 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001778 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001779 return 0;
1780 }
1781
1782 dir = opendir(path);
1783 if (!dir) {
1784 pr_debug("can't open pmu event dir");
1785 return -1;
1786 }
1787
1788 while (!ret && (ent = readdir(dir))) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001789 struct evlist_test e;
Arnaldo Carvalho de Melo2e2bbc032017-02-09 14:48:46 -03001790 char name[2 * NAME_MAX + 1 + 12 + 3];
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001791
Andi Kleen17a26342016-06-06 07:36:06 -07001792 /* Names containing . are special and cannot be used directly */
1793 if (strchr(ent->d_name, '.'))
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001794 continue;
1795
Arnaldo Carvalho de Melo2e2bbc032017-02-09 14:48:46 -03001796 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001797
1798 e.name = name;
1799 e.check = test__checkevent_pmu_events;
1800
1801 ret = test_event(&e);
Kan Liangffe59782014-10-07 11:08:52 -04001802 if (ret)
1803 break;
Arnaldo Carvalho de Melo2e2bbc032017-02-09 14:48:46 -03001804 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
Kan Liangffe59782014-10-07 11:08:52 -04001805 e.name = name;
1806 e.check = test__checkevent_pmu_events_mix;
1807 ret = test_event(&e);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001808 }
1809
1810 closedir(dir);
1811 return ret;
1812}
1813
Arnaldo Carvalho de Melo81f17c92017-08-03 15:16:31 -03001814int test__parse_events(struct test *test __maybe_unused, int subtest __maybe_unused)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001815{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001816 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001817
Jiri Olsaebf124f2012-07-04 00:00:47 +02001818#define TEST_EVENTS(tests) \
1819do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001820 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1821 if (!ret2) \
1822 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001823} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001824
Jiri Olsaebf124f2012-07-04 00:00:47 +02001825 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001826
Jiri Olsaebf124f2012-07-04 00:00:47 +02001827 if (test_pmu())
1828 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001829
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001830 if (test_pmu()) {
1831 int ret = test_pmu_events();
1832 if (ret)
1833 return ret;
1834 }
1835
Robert Richter9bfbbc62012-08-21 20:03:15 +02001836 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1837 if (!ret2)
1838 ret2 = ret1;
1839
1840 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001841}