blob: 9134a0c3e99dfa12e711d5388799213117c99271 [file] [log] [blame]
Jiri Olsaf50246e2012-05-21 09:12:49 +02001
2#include "parse-events.h"
3#include "evsel.h"
4#include "evlist.h"
Borislav Petkovcd0cfad2013-12-09 17:14:24 +01005#include <api/fs/fs.h>
Jiri Olsac81251e2012-11-10 01:46:51 +01006#include "tests.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02007#include "debug.h"
Namhyung Kim2690c732015-10-20 00:23:49 +09008#include "util.h"
David Howellsd2709c72012-11-19 22:21:03 +00009#include <linux/hw_breakpoint.h>
Jiri Olsa4605eab2015-09-02 09:56:43 +020010#include <api/fs/fs.h>
Jiri Olsaf50246e2012-05-21 09:12:49 +020011
Jiri Olsa30f31c02012-08-01 14:48:58 +020012#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
13 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
14
Thomas Richter9a501cd2019-06-04 07:35:04 +020015#if defined(__s390x__)
16/* Return true if kvm module is available and loaded. Test this
17 * and retun success when trace point kvm_s390_create_vm
18 * exists. Otherwise this test always fails.
19 */
20static bool kvm_s390_create_vm_valid(void)
21{
22 char *eventfile;
23 bool rc = false;
24
25 eventfile = get_events_file("kvm-s390");
26
27 if (eventfile) {
28 DIR *mydir = opendir(eventfile);
29
30 if (mydir) {
31 rc = true;
32 closedir(mydir);
33 }
34 put_events_file(eventfile);
35 }
36
37 return rc;
38}
39#endif
40
Jiri Olsaf50246e2012-05-21 09:12:49 +020041static int test__checkevent_tracepoint(struct perf_evlist *evlist)
42{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030043 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020044
45 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090046 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020047 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
48 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020049 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020050 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
51 return 0;
52}
53
54static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
55{
56 struct perf_evsel *evsel;
57
58 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
Namhyung Kim8d7d8472013-01-22 18:09:30 +090059 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
Jiri Olsaf50246e2012-05-21 09:12:49 +020060
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030061 evlist__for_each_entry(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +020062 TEST_ASSERT_VAL("wrong type",
63 PERF_TYPE_TRACEPOINT == evsel->attr.type);
64 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +020065 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +020066 TEST_ASSERT_VAL("wrong sample_period",
67 1 == evsel->attr.sample_period);
68 }
69 return 0;
70}
71
72static int test__checkevent_raw(struct perf_evlist *evlist)
73{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030074 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020075
76 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
77 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
78 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
79 return 0;
80}
81
82static int test__checkevent_numeric(struct perf_evlist *evlist)
83{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030084 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020085
86 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
87 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
88 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
89 return 0;
90}
91
92static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
93{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -030094 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +020095
96 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
97 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
98 TEST_ASSERT_VAL("wrong config",
99 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
100 return 0;
101}
102
103static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
104{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300105 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200106
107 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
108 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
109 TEST_ASSERT_VAL("wrong config",
110 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
Jiri Olsaee4c7582015-07-29 05:42:11 -0400111 /*
112 * The period value gets configured within perf_evlist__config,
113 * while this test executes only parse events method.
114 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200115 TEST_ASSERT_VAL("wrong period",
Jiri Olsaee4c7582015-07-29 05:42:11 -0400116 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200117 TEST_ASSERT_VAL("wrong config1",
118 0 == evsel->attr.config1);
119 TEST_ASSERT_VAL("wrong config2",
120 1 == evsel->attr.config2);
121 return 0;
122}
123
124static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
125{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300126 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200127
128 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
129 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
130 TEST_ASSERT_VAL("wrong config",
131 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
132 return 0;
133}
134
135static int test__checkevent_genhw(struct perf_evlist *evlist)
136{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300137 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200138
139 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
140 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
141 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
142 return 0;
143}
144
145static int test__checkevent_breakpoint(struct perf_evlist *evlist)
146{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300147 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200148
149 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
150 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
151 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
152 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
153 evsel->attr.bp_type);
154 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
155 evsel->attr.bp_len);
156 return 0;
157}
158
159static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
160{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300161 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200162
163 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
164 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
165 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
166 TEST_ASSERT_VAL("wrong bp_type",
167 HW_BREAKPOINT_X == evsel->attr.bp_type);
168 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
169 return 0;
170}
171
172static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
173{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300174 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200175
176 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
177 TEST_ASSERT_VAL("wrong type",
178 PERF_TYPE_BREAKPOINT == evsel->attr.type);
179 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
180 TEST_ASSERT_VAL("wrong bp_type",
181 HW_BREAKPOINT_R == evsel->attr.bp_type);
182 TEST_ASSERT_VAL("wrong bp_len",
183 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
184 return 0;
185}
186
187static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
188{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300189 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200190
191 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
192 TEST_ASSERT_VAL("wrong type",
193 PERF_TYPE_BREAKPOINT == evsel->attr.type);
194 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
195 TEST_ASSERT_VAL("wrong bp_type",
196 HW_BREAKPOINT_W == evsel->attr.bp_type);
197 TEST_ASSERT_VAL("wrong bp_len",
198 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
199 return 0;
200}
201
Jiri Olsa75827322012-06-29 09:22:54 +0200202static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
203{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300204 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200205
206 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
207 TEST_ASSERT_VAL("wrong type",
208 PERF_TYPE_BREAKPOINT == evsel->attr.type);
209 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
210 TEST_ASSERT_VAL("wrong bp_type",
211 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
212 TEST_ASSERT_VAL("wrong bp_len",
213 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
214 return 0;
215}
216
Jiri Olsaf50246e2012-05-21 09:12:49 +0200217static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
218{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300219 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200220
221 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
222 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
223 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
224 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
225
226 return test__checkevent_tracepoint(evlist);
227}
228
229static int
230test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
231{
232 struct perf_evsel *evsel;
233
234 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
235
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300236 evlist__for_each_entry(evlist, evsel) {
Jiri Olsaf50246e2012-05-21 09:12:49 +0200237 TEST_ASSERT_VAL("wrong exclude_user",
238 !evsel->attr.exclude_user);
239 TEST_ASSERT_VAL("wrong exclude_kernel",
240 evsel->attr.exclude_kernel);
241 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
242 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
243 }
244
245 return test__checkevent_tracepoint_multi(evlist);
246}
247
248static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
249{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300250 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200251
252 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
253 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
254 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
255 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
256
257 return test__checkevent_raw(evlist);
258}
259
260static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
261{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300262 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200263
264 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
265 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
266 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
267 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
268
269 return test__checkevent_numeric(evlist);
270}
271
272static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
273{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300274 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200275
276 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
277 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
278 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
279 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
280
281 return test__checkevent_symbolic_name(evlist);
282}
283
284static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
285{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300286 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200287
288 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
289 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
290
291 return test__checkevent_symbolic_name(evlist);
292}
293
294static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
295{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300296 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200297
298 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
299 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
300
301 return test__checkevent_symbolic_name(evlist);
302}
303
304static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
305{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300306 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200307
308 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
309 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
310 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
311 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
312
313 return test__checkevent_symbolic_alias(evlist);
314}
315
316static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
317{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300318 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200319
320 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
321 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
322 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
323 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
324
325 return test__checkevent_genhw(evlist);
326}
327
Jiri Olsaa1e12da2015-04-07 23:25:14 +0200328static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist)
329{
330 struct perf_evsel *evsel = perf_evlist__first(evlist);
331
332 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
333 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
334 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
335 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
336 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
337 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
338 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
339
340 return test__checkevent_symbolic_name(evlist);
341}
342
343static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist)
344{
345 struct perf_evsel *evsel = perf_evlist__first(evlist);
346
347 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
348 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
349 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
350 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
351 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
352 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
353 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
354
355 return test__checkevent_symbolic_name(evlist);
356}
357
Jiri Olsaf50246e2012-05-21 09:12:49 +0200358static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
359{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300360 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200361
Jiri Olsaf50246e2012-05-21 09:12:49 +0200362
363 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
364 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
365 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
366 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200367 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200368 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200369
370 return test__checkevent_breakpoint(evlist);
371}
372
373static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
374{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300375 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200376
377 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
378 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
379 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
380 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200381 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200382 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200383
384 return test__checkevent_breakpoint_x(evlist);
385}
386
387static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
388{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300389 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200390
391 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
392 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
393 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
394 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200395 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200396 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200397
398 return test__checkevent_breakpoint_r(evlist);
399}
400
401static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
402{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300403 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200404
405 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
406 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
407 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
408 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200409 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200410 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
Jiri Olsaf50246e2012-05-21 09:12:49 +0200411
412 return test__checkevent_breakpoint_w(evlist);
413}
414
Jiri Olsa75827322012-06-29 09:22:54 +0200415static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
416{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300417 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa75827322012-06-29 09:22:54 +0200418
419 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
420 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
421 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
422 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
Jiri Olsa287e74a2012-06-28 23:18:49 +0200423 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200424 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
Jiri Olsa75827322012-06-29 09:22:54 +0200425
426 return test__checkevent_breakpoint_rw(evlist);
427}
428
Jiri Olsaf50246e2012-05-21 09:12:49 +0200429static int test__checkevent_pmu(struct perf_evlist *evlist)
430{
431
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300432 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200433
434 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
435 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
436 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
437 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
438 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
Jiri Olsaee4c7582015-07-29 05:42:11 -0400439 /*
440 * The period value gets configured within perf_evlist__config,
441 * while this test executes only parse events method.
442 */
443 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200444
445 return 0;
446}
447
448static int test__checkevent_list(struct perf_evlist *evlist)
449{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300450 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200451
452 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
453
454 /* r1 */
Jiri Olsaf50246e2012-05-21 09:12:49 +0200455 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
456 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
457 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
458 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
459 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
460 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
461 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
462 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
463
Riku Voipio43f322b2015-04-16 16:52:53 +0300464 /* syscalls:sys_enter_openat:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300465 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200466 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
467 TEST_ASSERT_VAL("wrong sample_type",
Jiri Olsa30f31c02012-08-01 14:48:58 +0200468 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200469 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
470 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
471 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
472 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
473 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
474
475 /* 1:1:hp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300476 evsel = perf_evsel__next(evsel);
Jiri Olsaf50246e2012-05-21 09:12:49 +0200477 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
478 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
479 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
480 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
481 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
482 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
483
484 return 0;
485}
486
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200487static int test__checkevent_pmu_name(struct perf_evlist *evlist)
488{
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300489 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200490
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200491 /* cpu/config=1,name=krava/u */
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200492 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
493 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
494 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
Arnaldo Carvalho de Melo22c8b842012-06-12 13:55:13 -0300495 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200496
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200497 /* cpu/config=2/u" */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300498 evsel = perf_evsel__next(evsel);
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200499 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
500 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
501 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
Jiri Olsa7a25b2d2012-06-21 12:25:16 +0200502 TEST_ASSERT_VAL("wrong name",
Robert Richterac2ba9f2012-08-16 21:10:21 +0200503 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200504
505 return 0;
506}
507
Kan Liang71ef1502015-08-11 06:30:50 -0400508static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist)
509{
510 struct perf_evsel *evsel = perf_evlist__first(evlist);
511
512 /* cpu/config=1,call-graph=fp,time,period=100000/ */
513 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
514 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
515 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
516 /*
517 * The period, time and callgraph value gets configured
518 * within perf_evlist__config,
519 * while this test executes only parse events method.
520 */
521 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
522 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
523 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
524
525 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
526 evsel = perf_evsel__next(evsel);
527 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
528 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
529 /*
530 * The period, time and callgraph value gets configured
531 * within perf_evlist__config,
532 * while this test executes only parse events method.
533 */
534 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
535 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
536 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
537
538 return 0;
539}
540
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200541static int test__checkevent_pmu_events(struct perf_evlist *evlist)
542{
Arnaldo Carvalho de Melo9a354cd2013-11-13 15:54:30 -0300543 struct perf_evsel *evsel = perf_evlist__first(evlist);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200544
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200545 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
546 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
547 TEST_ASSERT_VAL("wrong exclude_user",
548 !evsel->attr.exclude_user);
549 TEST_ASSERT_VAL("wrong exclude_kernel",
550 evsel->attr.exclude_kernel);
551 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
552 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Michael Ellermanc9ee7802013-08-06 23:28:06 +1000553 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
Jiri Olsa3f3a2062012-10-10 14:53:18 +0200554
555 return 0;
556}
557
Kan Liangffe59782014-10-07 11:08:52 -0400558
559static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
560{
561 struct perf_evsel *evsel = perf_evlist__first(evlist);
562
563 /* pmu-event:u */
564 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
565 TEST_ASSERT_VAL("wrong exclude_user",
566 !evsel->attr.exclude_user);
567 TEST_ASSERT_VAL("wrong exclude_kernel",
568 evsel->attr.exclude_kernel);
569 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
570 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
571 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
572
573 /* cpu/pmu-event/u*/
574 evsel = perf_evsel__next(evsel);
575 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
576 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
577 TEST_ASSERT_VAL("wrong exclude_user",
578 !evsel->attr.exclude_user);
579 TEST_ASSERT_VAL("wrong exclude_kernel",
580 evsel->attr.exclude_kernel);
581 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
582 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
583 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
584
585 return 0;
586}
587
Jiri Olsa44293922012-06-15 14:31:42 +0800588static int test__checkterms_simple(struct list_head *terms)
589{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300590 struct parse_events_term *term;
Jiri Olsa44293922012-06-15 14:31:42 +0800591
592 /* config=10 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300593 term = list_entry(terms->next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800594 TEST_ASSERT_VAL("wrong type term",
595 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
596 TEST_ASSERT_VAL("wrong type val",
597 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
598 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
599 TEST_ASSERT_VAL("wrong config", !term->config);
600
601 /* config1 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300602 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800603 TEST_ASSERT_VAL("wrong type term",
604 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
605 TEST_ASSERT_VAL("wrong type val",
606 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
607 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
608 TEST_ASSERT_VAL("wrong config", !term->config);
609
610 /* config2=3 */
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300611 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800612 TEST_ASSERT_VAL("wrong type term",
613 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
614 TEST_ASSERT_VAL("wrong type val",
615 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
616 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
617 TEST_ASSERT_VAL("wrong config", !term->config);
618
619 /* umask=1*/
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300620 term = list_entry(term->list.next, struct parse_events_term, list);
Jiri Olsa44293922012-06-15 14:31:42 +0800621 TEST_ASSERT_VAL("wrong type term",
622 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
623 TEST_ASSERT_VAL("wrong type val",
624 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
625 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
626 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
627
628 return 0;
629}
630
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200631static int test__group1(struct perf_evlist *evlist)
632{
633 struct perf_evsel *evsel, *leader;
634
635 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900636 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200637
638 /* instructions:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300639 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200640 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
641 TEST_ASSERT_VAL("wrong config",
642 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
643 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
644 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
645 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
646 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
647 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
648 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900649 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900650 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
651 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100652 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200653
654 /* cycles:upp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300655 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200656 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
657 TEST_ASSERT_VAL("wrong config",
658 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
659 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
660 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
661 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200662 /* use of precise requires exclude_guest */
663 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200664 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
665 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
666 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900667 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100668 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200669
670 return 0;
671}
672
673static int test__group2(struct perf_evlist *evlist)
674{
675 struct perf_evsel *evsel, *leader;
676
677 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900678 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200679
680 /* faults + :ku modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300681 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200682 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
683 TEST_ASSERT_VAL("wrong config",
684 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
685 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
686 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
687 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
688 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
689 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
690 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900691 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900692 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
693 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100694 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200695
696 /* cache-references + :u modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300697 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200698 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
699 TEST_ASSERT_VAL("wrong config",
700 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
701 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
702 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
703 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa5a30a992013-02-04 10:56:43 +0100704 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200705 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
706 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
707 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900708 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100709 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200710
711 /* cycles:k */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300712 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200713 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
714 TEST_ASSERT_VAL("wrong config",
715 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
716 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
717 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
718 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
719 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
720 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
721 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900722 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100723 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200724
725 return 0;
726}
727
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300728static int test__group3(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200729{
730 struct perf_evsel *evsel, *leader;
731
732 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900733 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200734
Riku Voipio43f322b2015-04-16 16:52:53 +0300735 /* group1 syscalls:sys_enter_openat:H */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300736 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200737 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
738 TEST_ASSERT_VAL("wrong sample_type",
739 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
740 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
741 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
742 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
743 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
744 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
745 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
746 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900747 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200748 TEST_ASSERT_VAL("wrong group name",
749 !strcmp(leader->group_name, "group1"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900750 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
751 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100752 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200753
754 /* group1 cycles:kppp */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300755 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200756 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
757 TEST_ASSERT_VAL("wrong config",
758 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
759 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
760 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
761 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200762 /* use of precise requires exclude_guest */
763 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200764 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
765 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
766 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
767 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900768 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100769 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200770
771 /* group2 cycles + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300772 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200773 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
774 TEST_ASSERT_VAL("wrong config",
775 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
776 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
777 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
778 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
779 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
780 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
781 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900782 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200783 TEST_ASSERT_VAL("wrong group name",
784 !strcmp(leader->group_name, "group2"));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900785 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
786 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100787 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200788
789 /* group2 1:3 + G modifier */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300790 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200791 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
792 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
793 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
794 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
795 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
796 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
797 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
798 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
799 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900800 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100801 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200802
803 /* instructions:u */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300804 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200805 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
806 TEST_ASSERT_VAL("wrong config",
807 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
808 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
809 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
810 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
811 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
812 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
813 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900814 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100815 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200816
817 return 0;
818}
819
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300820static int test__group4(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200821{
822 struct perf_evsel *evsel, *leader;
823
824 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900825 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200826
827 /* cycles:u + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300828 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200829 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
830 TEST_ASSERT_VAL("wrong config",
831 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
832 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
833 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
834 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200835 /* use of precise requires exclude_guest */
836 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200837 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
838 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
839 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900840 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900841 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
842 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100843 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200844
845 /* instructions:kp + p */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300846 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200847 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
848 TEST_ASSERT_VAL("wrong config",
849 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
850 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
851 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
852 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
Jiri Olsa42be7392012-10-20 18:29:34 +0200853 /* use of precise requires exclude_guest */
854 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200855 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
856 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
857 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900858 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100859 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200860
861 return 0;
862}
863
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300864static int test__group5(struct perf_evlist *evlist __maybe_unused)
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200865{
866 struct perf_evsel *evsel, *leader;
867
868 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900869 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200870
871 /* cycles + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300872 evsel = leader = perf_evlist__first(evlist);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200873 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
874 TEST_ASSERT_VAL("wrong config",
875 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
876 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
877 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
878 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
879 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
880 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
881 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
882 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900883 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900884 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
885 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100886 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200887
888 /* instructions + G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300889 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200890 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
891 TEST_ASSERT_VAL("wrong config",
892 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
893 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
894 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
895 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
896 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
897 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
898 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
899 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900900 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100901 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200902
903 /* cycles:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300904 evsel = leader = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200905 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
906 TEST_ASSERT_VAL("wrong config",
907 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
908 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
909 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
910 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
911 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
912 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
913 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
914 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
Namhyung Kim823254e2012-11-29 15:38:30 +0900915 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900916 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
917 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
Jiri Olsaa9f93f92013-02-01 20:37:11 +0100918 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200919
920 /* instructions:G */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300921 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200922 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
923 TEST_ASSERT_VAL("wrong config",
924 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
925 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
926 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
927 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
928 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
929 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
930 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
931 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
Namhyung Kim8d7d8472013-01-22 18:09:30 +0900932 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200933
934 /* cycles */
Arnaldo Carvalho de Melo0c21f732012-08-14 16:42:15 -0300935 evsel = perf_evsel__next(evsel);
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200936 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
937 TEST_ASSERT_VAL("wrong config",
938 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
939 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
940 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
941 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
942 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
943 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
944 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
Namhyung Kim823254e2012-11-29 15:38:30 +0900945 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
Jiri Olsa905f5ee2012-08-08 12:23:52 +0200946
947 return 0;
948}
949
Jiri Olsa5a30a992013-02-04 10:56:43 +0100950static int test__group_gh1(struct perf_evlist *evlist)
951{
952 struct perf_evsel *evsel, *leader;
953
954 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
955 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
956
957 /* cycles + :H group modifier */
958 evsel = leader = perf_evlist__first(evlist);
959 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
960 TEST_ASSERT_VAL("wrong config",
961 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
962 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
963 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
964 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
965 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
966 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
967 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
968 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
969 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
970 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
971 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
972
973 /* cache-misses:G + :H group modifier */
974 evsel = perf_evsel__next(evsel);
975 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
976 TEST_ASSERT_VAL("wrong config",
977 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
978 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
979 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
980 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
981 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
982 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
983 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
984 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
985 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
986
987 return 0;
988}
989
990static int test__group_gh2(struct perf_evlist *evlist)
991{
992 struct perf_evsel *evsel, *leader;
993
994 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
995 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
996
997 /* cycles + :G group modifier */
998 evsel = leader = perf_evlist__first(evlist);
999 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1000 TEST_ASSERT_VAL("wrong config",
1001 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1002 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1003 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1004 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1005 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1006 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1007 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1008 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1009 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1010 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1011 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1012
1013 /* cache-misses:H + :G group modifier */
1014 evsel = perf_evsel__next(evsel);
1015 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1016 TEST_ASSERT_VAL("wrong config",
1017 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1018 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1019 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1020 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1021 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1022 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1023 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1024 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1025 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1026
1027 return 0;
1028}
1029
1030static int test__group_gh3(struct perf_evlist *evlist)
1031{
1032 struct perf_evsel *evsel, *leader;
1033
1034 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1035 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1036
1037 /* cycles:G + :u group modifier */
1038 evsel = leader = perf_evlist__first(evlist);
1039 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1040 TEST_ASSERT_VAL("wrong config",
1041 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1042 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1043 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1044 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1045 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1046 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1047 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1048 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1049 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1050 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1051 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1052
1053 /* cache-misses:H + :u group modifier */
1054 evsel = perf_evsel__next(evsel);
1055 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1056 TEST_ASSERT_VAL("wrong config",
1057 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1058 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1059 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1060 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1061 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1062 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1063 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1064 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1065 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1066
1067 return 0;
1068}
1069
1070static int test__group_gh4(struct perf_evlist *evlist)
1071{
1072 struct perf_evsel *evsel, *leader;
1073
1074 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1075 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1076
1077 /* cycles:G + :uG group modifier */
1078 evsel = leader = perf_evlist__first(evlist);
1079 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1080 TEST_ASSERT_VAL("wrong config",
1081 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1082 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1083 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1084 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1085 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1086 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1087 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1088 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1089 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1090 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1091 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1092
1093 /* cache-misses:H + :uG group modifier */
1094 evsel = perf_evsel__next(evsel);
1095 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1096 TEST_ASSERT_VAL("wrong config",
1097 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1098 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1099 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1100 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1101 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1102 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1103 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1104 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1105 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1106
1107 return 0;
1108}
1109
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001110static int test__leader_sample1(struct perf_evlist *evlist)
1111{
1112 struct perf_evsel *evsel, *leader;
1113
1114 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1115
1116 /* cycles - sampling group leader */
1117 evsel = leader = perf_evlist__first(evlist);
1118 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1119 TEST_ASSERT_VAL("wrong config",
1120 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1121 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1122 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1123 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1124 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1125 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1126 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1127 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1128 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1129 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1130
1131 /* cache-misses - not sampling */
1132 evsel = perf_evsel__next(evsel);
1133 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1134 TEST_ASSERT_VAL("wrong config",
1135 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1136 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1137 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1138 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1139 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1140 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1141 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1142 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1143 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1144
1145 /* branch-misses - not sampling */
1146 evsel = perf_evsel__next(evsel);
1147 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1148 TEST_ASSERT_VAL("wrong config",
1149 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1150 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1151 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1152 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1153 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1154 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1155 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1156 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1157 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1158 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1159
1160 return 0;
1161}
1162
1163static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1164{
1165 struct perf_evsel *evsel, *leader;
1166
1167 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1168
1169 /* instructions - sampling group leader */
1170 evsel = leader = perf_evlist__first(evlist);
1171 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1172 TEST_ASSERT_VAL("wrong config",
1173 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1174 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1175 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1176 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1177 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1178 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1179 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1180 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1181 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1182 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1183
1184 /* branch-misses - not sampling */
1185 evsel = perf_evsel__next(evsel);
1186 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1187 TEST_ASSERT_VAL("wrong config",
1188 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1189 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1190 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1191 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1192 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1193 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1194 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1195 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1196 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1197 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1198
1199 return 0;
1200}
1201
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001202static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1203{
1204 struct perf_evsel *evsel = perf_evlist__first(evlist);
1205
1206 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1207 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1208 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1209 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
1210 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1211
1212 return test__checkevent_symbolic_name(evlist);
1213}
1214
1215static int test__pinned_group(struct perf_evlist *evlist)
1216{
1217 struct perf_evsel *evsel, *leader;
1218
1219 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1220
1221 /* cycles - group leader */
1222 evsel = leader = perf_evlist__first(evlist);
1223 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1224 TEST_ASSERT_VAL("wrong config",
1225 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1226 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1227 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1228 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1229
1230 /* cache-misses - can not be pinned, but will go on with the leader */
1231 evsel = perf_evsel__next(evsel);
1232 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1233 TEST_ASSERT_VAL("wrong config",
1234 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1235 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1236
1237 /* branch-misses - ditto */
1238 evsel = perf_evsel__next(evsel);
1239 TEST_ASSERT_VAL("wrong config",
1240 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1241 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1242
1243 return 0;
1244}
1245
Jacob Shinec323982014-05-29 17:26:52 +02001246static int test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1247{
1248 struct perf_evsel *evsel = perf_evlist__first(evlist);
1249
1250 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1251 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1252 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1253 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1254 evsel->attr.bp_type);
1255 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1256 evsel->attr.bp_len);
1257
1258 return 0;
1259}
1260
1261static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1262{
1263 struct perf_evsel *evsel = perf_evlist__first(evlist);
1264
1265 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1266 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1267 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1268 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1269 evsel->attr.bp_type);
1270 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1271 evsel->attr.bp_len);
1272
1273 return 0;
1274}
1275
1276static int
1277test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1278{
1279 struct perf_evsel *evsel = perf_evlist__first(evlist);
1280
1281 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1282 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1283 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1284 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1285
1286 return test__checkevent_breakpoint_rw(evlist);
1287}
1288
Jiri Olsaddd83c92015-10-05 20:06:06 +02001289static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
1290{
1291 struct perf_evsel *evsel = perf_evlist__first(evlist);
1292
1293 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1294 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
1295 TEST_ASSERT_VAL("wrong config",
1296 PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config);
1297 return 0;
1298}
1299
Wang Nan10bf3582016-02-19 11:44:00 +00001300static int test__checkevent_config_symbol(struct perf_evlist *evlist)
1301{
1302 struct perf_evsel *evsel = perf_evlist__first(evlist);
1303
1304 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1305 return 0;
1306}
1307
1308static int test__checkevent_config_raw(struct perf_evlist *evlist)
1309{
1310 struct perf_evsel *evsel = perf_evlist__first(evlist);
1311
1312 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1313 return 0;
1314}
1315
1316static int test__checkevent_config_num(struct perf_evlist *evlist)
1317{
1318 struct perf_evsel *evsel = perf_evlist__first(evlist);
1319
1320 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1321 return 0;
1322}
1323
Wang Nan43d0b972016-02-19 11:44:01 +00001324static int test__checkevent_config_cache(struct perf_evlist *evlist)
1325{
1326 struct perf_evsel *evsel = perf_evlist__first(evlist);
1327
1328 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1329 return 0;
1330}
Wang Nan10bf3582016-02-19 11:44:00 +00001331
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001332static int count_tracepoints(void)
1333{
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001334 struct dirent *events_ent;
1335 DIR *events_dir;
1336 int cnt = 0;
1337
Jiri Olsafbf99622015-09-02 09:56:45 +02001338 events_dir = opendir(tracing_events_path);
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001339
1340 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1341
1342 while ((events_ent = readdir(events_dir))) {
1343 char sys_path[PATH_MAX];
1344 struct dirent *sys_ent;
1345 DIR *sys_dir;
1346
1347 if (!strcmp(events_ent->d_name, ".")
1348 || !strcmp(events_ent->d_name, "..")
1349 || !strcmp(events_ent->d_name, "enable")
1350 || !strcmp(events_ent->d_name, "header_event")
1351 || !strcmp(events_ent->d_name, "header_page"))
1352 continue;
1353
1354 scnprintf(sys_path, PATH_MAX, "%s/%s",
Jiri Olsafbf99622015-09-02 09:56:45 +02001355 tracing_events_path, events_ent->d_name);
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001356
1357 sys_dir = opendir(sys_path);
1358 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1359
1360 while ((sys_ent = readdir(sys_dir))) {
1361 if (!strcmp(sys_ent->d_name, ".")
1362 || !strcmp(sys_ent->d_name, "..")
1363 || !strcmp(sys_ent->d_name, "enable")
1364 || !strcmp(sys_ent->d_name, "filter"))
1365 continue;
1366
1367 cnt++;
1368 }
1369
1370 closedir(sys_dir);
1371 }
1372
1373 closedir(events_dir);
1374 return cnt;
1375}
1376
1377static int test__all_tracepoints(struct perf_evlist *evlist)
1378{
1379 TEST_ASSERT_VAL("wrong events count",
1380 count_tracepoints() == evlist->nr_entries);
1381
1382 return test__checkevent_tracepoint_multi(evlist);
1383}
1384
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001385struct evlist_test {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001386 const char *name;
1387 __u32 type;
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001388 const int id;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001389 int (*check)(struct perf_evlist *evlist);
1390};
1391
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001392static struct evlist_test test__events[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001393 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001394 .name = "syscalls:sys_enter_openat",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001395 .check = test__checkevent_tracepoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001396 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001397 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001398 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001399 .name = "syscalls:*",
1400 .check = test__checkevent_tracepoint_multi,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001401 .id = 1,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001402 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001403 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001404 .name = "r1a",
1405 .check = test__checkevent_raw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001406 .id = 2,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001407 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001408 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001409 .name = "1:1",
1410 .check = test__checkevent_numeric,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001411 .id = 3,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001412 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001413 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001414 .name = "instructions",
1415 .check = test__checkevent_symbolic_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001416 .id = 4,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001417 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001418 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001419 .name = "cycles/period=100000,config2/",
1420 .check = test__checkevent_symbolic_name_config,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001421 .id = 5,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001422 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001423 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001424 .name = "faults",
1425 .check = test__checkevent_symbolic_alias,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001426 .id = 6,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001427 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001428 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001429 .name = "L1-dcache-load-miss",
1430 .check = test__checkevent_genhw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001431 .id = 7,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001432 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001433 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001434 .name = "mem:0",
1435 .check = test__checkevent_breakpoint,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001436 .id = 8,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001437 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001438 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001439 .name = "mem:0:x",
1440 .check = test__checkevent_breakpoint_x,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001441 .id = 9,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001442 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001443 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001444 .name = "mem:0:r",
1445 .check = test__checkevent_breakpoint_r,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001446 .id = 10,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001447 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001448 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001449 .name = "mem:0:w",
1450 .check = test__checkevent_breakpoint_w,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001451 .id = 11,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001452 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001453 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001454 .name = "syscalls:sys_enter_openat:k",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001455 .check = test__checkevent_tracepoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001456 .id = 12,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001457 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001458 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001459 .name = "syscalls:*:u",
1460 .check = test__checkevent_tracepoint_multi_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001461 .id = 13,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001462 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001463 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001464 .name = "r1a:kp",
1465 .check = test__checkevent_raw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001466 .id = 14,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001467 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001468 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001469 .name = "1:1:hp",
1470 .check = test__checkevent_numeric_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001471 .id = 15,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001472 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001473 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001474 .name = "instructions:h",
1475 .check = test__checkevent_symbolic_name_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001476 .id = 16,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001477 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001478 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001479 .name = "faults:u",
1480 .check = test__checkevent_symbolic_alias_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001481 .id = 17,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001482 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001483 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001484 .name = "L1-dcache-load-miss:kp",
1485 .check = test__checkevent_genhw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001486 .id = 18,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001487 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001488 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001489 .name = "mem:0:u",
1490 .check = test__checkevent_breakpoint_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001491 .id = 19,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001492 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001493 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001494 .name = "mem:0:x:k",
1495 .check = test__checkevent_breakpoint_x_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001496 .id = 20,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001497 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001498 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001499 .name = "mem:0:r:hp",
1500 .check = test__checkevent_breakpoint_r_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001501 .id = 21,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001502 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001503 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001504 .name = "mem:0:w:up",
1505 .check = test__checkevent_breakpoint_w_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001506 .id = 22,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001507 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001508 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001509 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
Jiri Olsaf50246e2012-05-21 09:12:49 +02001510 .check = test__checkevent_list,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001511 .id = 23,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001512 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001513 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001514 .name = "instructions:G",
1515 .check = test__checkevent_exclude_host_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001516 .id = 24,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001517 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001518 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001519 .name = "instructions:H",
1520 .check = test__checkevent_exclude_guest_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001521 .id = 25,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001522 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001523 {
Jiri Olsa75827322012-06-29 09:22:54 +02001524 .name = "mem:0:rw",
1525 .check = test__checkevent_breakpoint_rw,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001526 .id = 26,
Jiri Olsa75827322012-06-29 09:22:54 +02001527 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001528 {
Jiri Olsa75827322012-06-29 09:22:54 +02001529 .name = "mem:0:rw:kp",
1530 .check = test__checkevent_breakpoint_rw_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001531 .id = 27,
Jiri Olsa75827322012-06-29 09:22:54 +02001532 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001533 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001534 .name = "{instructions:k,cycles:upp}",
1535 .check = test__group1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001536 .id = 28,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001537 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001538 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001539 .name = "{faults:k,cache-references}:u,cycles:k",
1540 .check = test__group2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001541 .id = 29,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001542 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001543 {
Riku Voipio43f322b2015-04-16 16:52:53 +03001544 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001545 .check = test__group3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001546 .id = 30,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001547 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001548 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001549 .name = "{cycles:u,instructions:kp}:p",
1550 .check = test__group4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001551 .id = 31,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001552 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001553 {
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001554 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1555 .check = test__group5,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001556 .id = 32,
Jiri Olsa905f5ee2012-08-08 12:23:52 +02001557 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001558 {
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001559 .name = "*:*",
1560 .check = test__all_tracepoints,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001561 .id = 33,
Jiri Olsa82ce75d2012-12-17 14:08:38 +01001562 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001563 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001564 .name = "{cycles,cache-misses:G}:H",
1565 .check = test__group_gh1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001566 .id = 34,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001567 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001568 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001569 .name = "{cycles,cache-misses:H}:G",
1570 .check = test__group_gh2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001571 .id = 35,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001572 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001573 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001574 .name = "{cycles:G,cache-misses:H}:u",
1575 .check = test__group_gh3,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001576 .id = 36,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001577 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001578 {
Jiri Olsa5a30a992013-02-04 10:56:43 +01001579 .name = "{cycles:G,cache-misses:H}:uG",
1580 .check = test__group_gh4,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001581 .id = 37,
Jiri Olsa5a30a992013-02-04 10:56:43 +01001582 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001583 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001584 .name = "{cycles,cache-misses,branch-misses}:S",
1585 .check = test__leader_sample1,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001586 .id = 38,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001587 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001588 {
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001589 .name = "{instructions,branch-misses}:Su",
1590 .check = test__leader_sample2,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001591 .id = 39,
Jiri Olsaa9f93f92013-02-01 20:37:11 +01001592 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001593 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001594 .name = "instructions:uDp",
1595 .check = test__checkevent_pinned_modifier,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001596 .id = 40,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001597 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001598 {
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001599 .name = "{cycles,cache-misses,branch-misses}:D",
1600 .check = test__pinned_group,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001601 .id = 41,
Michael Ellermanc9ee7802013-08-06 23:28:06 +10001602 },
Jacob Shinec323982014-05-29 17:26:52 +02001603 {
1604 .name = "mem:0/1",
1605 .check = test__checkevent_breakpoint_len,
1606 .id = 42,
1607 },
1608 {
1609 .name = "mem:0/2:w",
1610 .check = test__checkevent_breakpoint_len_w,
1611 .id = 43,
1612 },
1613 {
1614 .name = "mem:0/4:rw:u",
1615 .check = test__checkevent_breakpoint_len_rw_modifier,
1616 .id = 44
1617 },
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001618#if defined(__s390x__)
1619 {
1620 .name = "kvm-s390:kvm_s390_create_vm",
1621 .check = test__checkevent_tracepoint,
Thomas Richter9a501cd2019-06-04 07:35:04 +02001622 .valid = kvm_s390_create_vm_valid,
Alexander Yaryginc0bc8c62014-04-25 17:34:07 +02001623 .id = 100,
1624 },
1625#endif
Jiri Olsaa1e12da2015-04-07 23:25:14 +02001626 {
1627 .name = "instructions:I",
1628 .check = test__checkevent_exclude_idle_modifier,
1629 .id = 45,
1630 },
1631 {
1632 .name = "instructions:kIG",
1633 .check = test__checkevent_exclude_idle_modifier_1,
1634 .id = 46,
1635 },
Jiri Olsaddd83c92015-10-05 20:06:06 +02001636 {
1637 .name = "task-clock:P,cycles",
1638 .check = test__checkevent_precise_max_modifier,
1639 .id = 47,
1640 },
Wang Nan10bf3582016-02-19 11:44:00 +00001641 {
1642 .name = "instructions/name=insn/",
1643 .check = test__checkevent_config_symbol,
1644 .id = 48,
1645 },
1646 {
1647 .name = "r1234/name=rawpmu/",
1648 .check = test__checkevent_config_raw,
1649 .id = 49,
1650 },
1651 {
1652 .name = "4:0x6530160/name=numpmu/",
1653 .check = test__checkevent_config_num,
1654 .id = 50,
1655 },
Wang Nan43d0b972016-02-19 11:44:01 +00001656 {
1657 .name = "L1-dcache-misses/name=cachepmu/",
1658 .check = test__checkevent_config_cache,
1659 .id = 51,
1660 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001661};
1662
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001663static struct evlist_test test__events_pmu[] = {
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001664 {
Jiri Olsaf50246e2012-05-21 09:12:49 +02001665 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1666 .check = test__checkevent_pmu,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001667 .id = 0,
Jiri Olsaf50246e2012-05-21 09:12:49 +02001668 },
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001669 {
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001670 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1671 .check = test__checkevent_pmu_name,
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001672 .id = 1,
Jiri Olsa6b5fc392012-05-21 09:12:53 +02001673 },
Kan Liang71ef1502015-08-11 06:30:50 -04001674 {
1675 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1676 .check = test__checkevent_pmu_partial_time_callgraph,
1677 .id = 2,
1678 },
Jiri Olsaf50246e2012-05-21 09:12:49 +02001679};
1680
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001681struct terms_test {
Jiri Olsa44293922012-06-15 14:31:42 +08001682 const char *str;
1683 __u32 type;
1684 int (*check)(struct list_head *terms);
1685};
1686
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001687static struct terms_test test__terms[] = {
Jiri Olsa44293922012-06-15 14:31:42 +08001688 [0] = {
1689 .str = "config=10,config1,config2=3,umask=1",
1690 .check = test__checkterms_simple,
1691 },
1692};
1693
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001694static int test_event(struct evlist_test *e)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001695{
1696 struct perf_evlist *evlist;
1697 int ret;
1698
Namhyung Kim334fe7a2013-03-11 16:43:12 +09001699 evlist = perf_evlist__new();
Jiri Olsaf50246e2012-05-21 09:12:49 +02001700 if (evlist == NULL)
1701 return -ENOMEM;
1702
Jiri Olsab39b8392015-04-22 21:10:16 +02001703 ret = parse_events(evlist, e->name, NULL);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001704 if (ret) {
1705 pr_debug("failed to parse event '%s', err %d\n",
1706 e->name, ret);
Arnaldo Carvalho de Melo2d4352c2014-01-03 17:30:04 -03001707 } else {
1708 ret = e->check(evlist);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001709 }
Arnaldo Carvalho de Melo48000a12014-12-17 17:24:45 -03001710
Jiri Olsaf50246e2012-05-21 09:12:49 +02001711 perf_evlist__delete(evlist);
1712
1713 return ret;
1714}
1715
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001716static int test_events(struct evlist_test *events, unsigned cnt)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001717{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001718 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001719 unsigned i;
1720
1721 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001722 struct evlist_test *e = &events[i];
Jiri Olsaf50246e2012-05-21 09:12:49 +02001723
Alexander Yarygin615b8f92014-04-25 17:34:06 +02001724 pr_debug("running test %d '%s'\n", e->id, e->name);
Robert Richter9bfbbc62012-08-21 20:03:15 +02001725 ret1 = test_event(e);
1726 if (ret1)
1727 ret2 = ret1;
Jiri Olsa44293922012-06-15 14:31:42 +08001728 }
1729
Robert Richter9bfbbc62012-08-21 20:03:15 +02001730 return ret2;
Jiri Olsa44293922012-06-15 14:31:42 +08001731}
1732
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001733static int test_term(struct terms_test *t)
Jiri Olsa44293922012-06-15 14:31:42 +08001734{
David Ahernc549aca2013-07-02 13:27:24 -06001735 struct list_head terms;
Jiri Olsa44293922012-06-15 14:31:42 +08001736 int ret;
1737
David Ahernc549aca2013-07-02 13:27:24 -06001738 INIT_LIST_HEAD(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001739
David Ahernc549aca2013-07-02 13:27:24 -06001740 ret = parse_events_terms(&terms, t->str);
Jiri Olsa44293922012-06-15 14:31:42 +08001741 if (ret) {
1742 pr_debug("failed to parse terms '%s', err %d\n",
1743 t->str , ret);
1744 return ret;
1745 }
1746
David Ahernc549aca2013-07-02 13:27:24 -06001747 ret = t->check(&terms);
Arnaldo Carvalho de Melo682dc242016-02-12 16:48:00 -03001748 parse_events_terms__purge(&terms);
Jiri Olsa44293922012-06-15 14:31:42 +08001749
1750 return ret;
1751}
1752
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001753static int test_terms(struct terms_test *terms, unsigned cnt)
Jiri Olsa44293922012-06-15 14:31:42 +08001754{
1755 int ret = 0;
1756 unsigned i;
1757
1758 for (i = 0; i < cnt; i++) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001759 struct terms_test *t = &terms[i];
Jiri Olsa44293922012-06-15 14:31:42 +08001760
1761 pr_debug("running test %d '%s'\n", i, t->str);
1762 ret = test_term(t);
Jiri Olsaf50246e2012-05-21 09:12:49 +02001763 if (ret)
1764 break;
1765 }
1766
1767 return ret;
1768}
1769
1770static int test_pmu(void)
1771{
1772 struct stat st;
1773 char path[PATH_MAX];
1774 int ret;
1775
1776 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001777 sysfs__mountpoint());
Jiri Olsaf50246e2012-05-21 09:12:49 +02001778
1779 ret = stat(path, &st);
1780 if (ret)
Masanari Iida3fd44cd2012-07-18 01:20:59 +09001781 pr_debug("omitting PMU cpu tests\n");
Jiri Olsaf50246e2012-05-21 09:12:49 +02001782 return !ret;
1783}
1784
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001785static int test_pmu_events(void)
1786{
1787 struct stat st;
1788 char path[PATH_MAX];
1789 struct dirent *ent;
1790 DIR *dir;
1791 int ret;
1792
1793 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
Arnaldo Carvalho de Melocf38fad2013-11-05 14:48:50 -03001794 sysfs__mountpoint());
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001795
1796 ret = stat(path, &st);
1797 if (ret) {
Masanari Iidaa895d572013-04-09 02:06:50 +09001798 pr_debug("omitting PMU cpu events tests\n");
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001799 return 0;
1800 }
1801
1802 dir = opendir(path);
1803 if (!dir) {
1804 pr_debug("can't open pmu event dir");
1805 return -1;
1806 }
1807
1808 while (!ret && (ent = readdir(dir))) {
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -03001809 struct evlist_test e;
Arnaldo Carvalho de Melob246fc02017-02-09 14:48:46 -03001810 char name[2 * NAME_MAX + 1 + 12 + 3];
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001811
Andi Kleen17a26342016-06-06 07:36:06 -07001812 /* Names containing . are special and cannot be used directly */
1813 if (strchr(ent->d_name, '.'))
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001814 continue;
1815
Arnaldo Carvalho de Melob246fc02017-02-09 14:48:46 -03001816 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001817
1818 e.name = name;
1819 e.check = test__checkevent_pmu_events;
1820
1821 ret = test_event(&e);
Kan Liangffe59782014-10-07 11:08:52 -04001822 if (ret)
1823 break;
Arnaldo Carvalho de Melob246fc02017-02-09 14:48:46 -03001824 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
Kan Liangffe59782014-10-07 11:08:52 -04001825 e.name = name;
1826 e.check = test__checkevent_pmu_events_mix;
1827 ret = test_event(&e);
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001828 }
1829
1830 closedir(dir);
1831 return ret;
1832}
1833
Namhyung Kim2690c732015-10-20 00:23:49 +09001834static void debug_warn(const char *warn, va_list params)
1835{
1836 char msg[1024];
1837
1838 if (!verbose)
1839 return;
1840
1841 vsnprintf(msg, sizeof(msg), warn, params);
1842 fprintf(stderr, " Warning: %s\n", msg);
1843}
1844
Arnaldo Carvalho de Melo721a1f52015-11-19 12:01:48 -03001845int test__parse_events(int subtest __maybe_unused)
Jiri Olsaf50246e2012-05-21 09:12:49 +02001846{
Robert Richter9bfbbc62012-08-21 20:03:15 +02001847 int ret1, ret2 = 0;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001848
Jiri Olsaebf124f2012-07-04 00:00:47 +02001849#define TEST_EVENTS(tests) \
1850do { \
Robert Richter9bfbbc62012-08-21 20:03:15 +02001851 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1852 if (!ret2) \
1853 ret2 = ret1; \
Jiri Olsaebf124f2012-07-04 00:00:47 +02001854} while (0)
Jiri Olsa44293922012-06-15 14:31:42 +08001855
Namhyung Kim2690c732015-10-20 00:23:49 +09001856 set_warning_routine(debug_warn);
1857
Jiri Olsaebf124f2012-07-04 00:00:47 +02001858 TEST_EVENTS(test__events);
Jiri Olsa44293922012-06-15 14:31:42 +08001859
Jiri Olsaebf124f2012-07-04 00:00:47 +02001860 if (test_pmu())
1861 TEST_EVENTS(test__events_pmu);
Jiri Olsa44293922012-06-15 14:31:42 +08001862
Jiri Olsa3f3a2062012-10-10 14:53:18 +02001863 if (test_pmu()) {
1864 int ret = test_pmu_events();
1865 if (ret)
1866 return ret;
1867 }
1868
Robert Richter9bfbbc62012-08-21 20:03:15 +02001869 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1870 if (!ret2)
1871 ret2 = ret1;
1872
1873 return ret2;
Jiri Olsaf50246e2012-05-21 09:12:49 +02001874}