Commit | Line | Data |
---|---|---|
f50246e2 JO |
1 | |
2 | #include "parse-events.h" | |
3 | #include "evsel.h" | |
4 | #include "evlist.h" | |
5 | #include "sysfs.h" | |
82ce75d9 | 6 | #include "debugfs.h" |
c81251e8 | 7 | #include "tests.h" |
d2709c7c | 8 | #include <linux/hw_breakpoint.h> |
f50246e2 JO |
9 | |
10 | #define TEST_ASSERT_VAL(text, cond) \ | |
11 | do { \ | |
12 | if (!(cond)) { \ | |
13 | pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \ | |
14 | return -1; \ | |
15 | } \ | |
16 | } while (0) | |
17 | ||
30f31c0a JO |
18 | #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ |
19 | PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) | |
20 | ||
f50246e2 JO |
21 | static int test__checkevent_tracepoint(struct perf_evlist *evlist) |
22 | { | |
0c21f736 | 23 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
24 | |
25 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
8d7d8474 | 26 | TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups); |
f50246e2 JO |
27 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); |
28 | TEST_ASSERT_VAL("wrong sample_type", | |
30f31c0a | 29 | PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); |
f50246e2 JO |
30 | TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); |
31 | return 0; | |
32 | } | |
33 | ||
34 | static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist) | |
35 | { | |
36 | struct perf_evsel *evsel; | |
37 | ||
38 | TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); | |
8d7d8474 | 39 | TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups); |
f50246e2 JO |
40 | |
41 | list_for_each_entry(evsel, &evlist->entries, node) { | |
42 | TEST_ASSERT_VAL("wrong type", | |
43 | PERF_TYPE_TRACEPOINT == evsel->attr.type); | |
44 | TEST_ASSERT_VAL("wrong sample_type", | |
30f31c0a | 45 | PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); |
f50246e2 JO |
46 | TEST_ASSERT_VAL("wrong sample_period", |
47 | 1 == evsel->attr.sample_period); | |
48 | } | |
49 | return 0; | |
50 | } | |
51 | ||
52 | static int test__checkevent_raw(struct perf_evlist *evlist) | |
53 | { | |
0c21f736 | 54 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
55 | |
56 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
57 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | |
58 | TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config); | |
59 | return 0; | |
60 | } | |
61 | ||
62 | static int test__checkevent_numeric(struct perf_evlist *evlist) | |
63 | { | |
0c21f736 | 64 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
65 | |
66 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
67 | TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); | |
68 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); | |
69 | return 0; | |
70 | } | |
71 | ||
72 | static int test__checkevent_symbolic_name(struct perf_evlist *evlist) | |
73 | { | |
0c21f736 | 74 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
75 | |
76 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
77 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
78 | TEST_ASSERT_VAL("wrong config", | |
79 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist) | |
84 | { | |
0c21f736 | 85 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
86 | |
87 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
88 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
89 | TEST_ASSERT_VAL("wrong config", | |
90 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
91 | TEST_ASSERT_VAL("wrong period", | |
92 | 100000 == evsel->attr.sample_period); | |
93 | TEST_ASSERT_VAL("wrong config1", | |
94 | 0 == evsel->attr.config1); | |
95 | TEST_ASSERT_VAL("wrong config2", | |
96 | 1 == evsel->attr.config2); | |
97 | return 0; | |
98 | } | |
99 | ||
100 | static int test__checkevent_symbolic_alias(struct perf_evlist *evlist) | |
101 | { | |
0c21f736 | 102 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
103 | |
104 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
105 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); | |
106 | TEST_ASSERT_VAL("wrong config", | |
107 | PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config); | |
108 | return 0; | |
109 | } | |
110 | ||
111 | static int test__checkevent_genhw(struct perf_evlist *evlist) | |
112 | { | |
0c21f736 | 113 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
114 | |
115 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
116 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type); | |
117 | TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | static int test__checkevent_breakpoint(struct perf_evlist *evlist) | |
122 | { | |
0c21f736 | 123 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
124 | |
125 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
126 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); | |
127 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); | |
128 | TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == | |
129 | evsel->attr.bp_type); | |
130 | TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 == | |
131 | evsel->attr.bp_len); | |
132 | return 0; | |
133 | } | |
134 | ||
135 | static int test__checkevent_breakpoint_x(struct perf_evlist *evlist) | |
136 | { | |
0c21f736 | 137 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
138 | |
139 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
140 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); | |
141 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); | |
142 | TEST_ASSERT_VAL("wrong bp_type", | |
143 | HW_BREAKPOINT_X == evsel->attr.bp_type); | |
144 | TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len); | |
145 | return 0; | |
146 | } | |
147 | ||
148 | static int test__checkevent_breakpoint_r(struct perf_evlist *evlist) | |
149 | { | |
0c21f736 | 150 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
151 | |
152 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
153 | TEST_ASSERT_VAL("wrong type", | |
154 | PERF_TYPE_BREAKPOINT == evsel->attr.type); | |
155 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); | |
156 | TEST_ASSERT_VAL("wrong bp_type", | |
157 | HW_BREAKPOINT_R == evsel->attr.bp_type); | |
158 | TEST_ASSERT_VAL("wrong bp_len", | |
159 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); | |
160 | return 0; | |
161 | } | |
162 | ||
163 | static int test__checkevent_breakpoint_w(struct perf_evlist *evlist) | |
164 | { | |
0c21f736 | 165 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
166 | |
167 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
168 | TEST_ASSERT_VAL("wrong type", | |
169 | PERF_TYPE_BREAKPOINT == evsel->attr.type); | |
170 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); | |
171 | TEST_ASSERT_VAL("wrong bp_type", | |
172 | HW_BREAKPOINT_W == evsel->attr.bp_type); | |
173 | TEST_ASSERT_VAL("wrong bp_len", | |
174 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); | |
175 | return 0; | |
176 | } | |
177 | ||
7582732f JO |
178 | static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist) |
179 | { | |
0c21f736 | 180 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
7582732f JO |
181 | |
182 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
183 | TEST_ASSERT_VAL("wrong type", | |
184 | PERF_TYPE_BREAKPOINT == evsel->attr.type); | |
185 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); | |
186 | TEST_ASSERT_VAL("wrong bp_type", | |
187 | (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type); | |
188 | TEST_ASSERT_VAL("wrong bp_len", | |
189 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); | |
190 | return 0; | |
191 | } | |
192 | ||
f50246e2 JO |
193 | static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist) |
194 | { | |
0c21f736 | 195 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
196 | |
197 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
198 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
199 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
200 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
201 | ||
202 | return test__checkevent_tracepoint(evlist); | |
203 | } | |
204 | ||
205 | static int | |
206 | test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist) | |
207 | { | |
208 | struct perf_evsel *evsel; | |
209 | ||
210 | TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); | |
211 | ||
212 | list_for_each_entry(evsel, &evlist->entries, node) { | |
213 | TEST_ASSERT_VAL("wrong exclude_user", | |
214 | !evsel->attr.exclude_user); | |
215 | TEST_ASSERT_VAL("wrong exclude_kernel", | |
216 | evsel->attr.exclude_kernel); | |
217 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
218 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
219 | } | |
220 | ||
221 | return test__checkevent_tracepoint_multi(evlist); | |
222 | } | |
223 | ||
224 | static int test__checkevent_raw_modifier(struct perf_evlist *evlist) | |
225 | { | |
0c21f736 | 226 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
227 | |
228 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
229 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
230 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
231 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
232 | ||
233 | return test__checkevent_raw(evlist); | |
234 | } | |
235 | ||
236 | static int test__checkevent_numeric_modifier(struct perf_evlist *evlist) | |
237 | { | |
0c21f736 | 238 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
239 | |
240 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
241 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
242 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
243 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
244 | ||
245 | return test__checkevent_numeric(evlist); | |
246 | } | |
247 | ||
248 | static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist) | |
249 | { | |
0c21f736 | 250 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
251 | |
252 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
253 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
254 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
255 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
256 | ||
257 | return test__checkevent_symbolic_name(evlist); | |
258 | } | |
259 | ||
260 | static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist) | |
261 | { | |
0c21f736 | 262 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
263 | |
264 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
265 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
266 | ||
267 | return test__checkevent_symbolic_name(evlist); | |
268 | } | |
269 | ||
270 | static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist) | |
271 | { | |
0c21f736 | 272 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
273 | |
274 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
275 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
276 | ||
277 | return test__checkevent_symbolic_name(evlist); | |
278 | } | |
279 | ||
280 | static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist) | |
281 | { | |
0c21f736 | 282 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
283 | |
284 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
285 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
286 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
287 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
288 | ||
289 | return test__checkevent_symbolic_alias(evlist); | |
290 | } | |
291 | ||
292 | static int test__checkevent_genhw_modifier(struct perf_evlist *evlist) | |
293 | { | |
0c21f736 | 294 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
295 | |
296 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
297 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
298 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
299 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
300 | ||
301 | return test__checkevent_genhw(evlist); | |
302 | } | |
303 | ||
304 | static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist) | |
305 | { | |
0c21f736 | 306 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 | 307 | |
f50246e2 JO |
308 | |
309 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
310 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
311 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
312 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
287e74aa | 313 | TEST_ASSERT_VAL("wrong name", |
ac2ba9f3 | 314 | !strcmp(perf_evsel__name(evsel), "mem:0:u")); |
f50246e2 JO |
315 | |
316 | return test__checkevent_breakpoint(evlist); | |
317 | } | |
318 | ||
319 | static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist) | |
320 | { | |
0c21f736 | 321 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
322 | |
323 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
324 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
325 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
326 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
287e74aa | 327 | TEST_ASSERT_VAL("wrong name", |
ac2ba9f3 | 328 | !strcmp(perf_evsel__name(evsel), "mem:0:x:k")); |
f50246e2 JO |
329 | |
330 | return test__checkevent_breakpoint_x(evlist); | |
331 | } | |
332 | ||
333 | static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist) | |
334 | { | |
0c21f736 | 335 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
336 | |
337 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
338 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
339 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
340 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
287e74aa | 341 | TEST_ASSERT_VAL("wrong name", |
ac2ba9f3 | 342 | !strcmp(perf_evsel__name(evsel), "mem:0:r:hp")); |
f50246e2 JO |
343 | |
344 | return test__checkevent_breakpoint_r(evlist); | |
345 | } | |
346 | ||
347 | static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist) | |
348 | { | |
0c21f736 | 349 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
350 | |
351 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
352 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
353 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
354 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
287e74aa | 355 | TEST_ASSERT_VAL("wrong name", |
ac2ba9f3 | 356 | !strcmp(perf_evsel__name(evsel), "mem:0:w:up")); |
f50246e2 JO |
357 | |
358 | return test__checkevent_breakpoint_w(evlist); | |
359 | } | |
360 | ||
7582732f JO |
361 | static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist) |
362 | { | |
0c21f736 | 363 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
7582732f JO |
364 | |
365 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
366 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
367 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
368 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
287e74aa | 369 | TEST_ASSERT_VAL("wrong name", |
ac2ba9f3 | 370 | !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp")); |
7582732f JO |
371 | |
372 | return test__checkevent_breakpoint_rw(evlist); | |
373 | } | |
374 | ||
f50246e2 JO |
375 | static int test__checkevent_pmu(struct perf_evlist *evlist) |
376 | { | |
377 | ||
0c21f736 | 378 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
379 | |
380 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
381 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | |
382 | TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config); | |
383 | TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1); | |
384 | TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2); | |
385 | TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period); | |
386 | ||
387 | return 0; | |
388 | } | |
389 | ||
390 | static int test__checkevent_list(struct perf_evlist *evlist) | |
391 | { | |
0c21f736 | 392 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
f50246e2 JO |
393 | |
394 | TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); | |
395 | ||
396 | /* r1 */ | |
f50246e2 JO |
397 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
398 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); | |
399 | TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1); | |
400 | TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2); | |
401 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
402 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
403 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
404 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
405 | ||
406 | /* syscalls:sys_enter_open:k */ | |
0c21f736 | 407 | evsel = perf_evsel__next(evsel); |
f50246e2 JO |
408 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); |
409 | TEST_ASSERT_VAL("wrong sample_type", | |
30f31c0a | 410 | PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); |
f50246e2 JO |
411 | TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); |
412 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
413 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
414 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
415 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
416 | ||
417 | /* 1:1:hp */ | |
0c21f736 | 418 | evsel = perf_evsel__next(evsel); |
f50246e2 JO |
419 | TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); |
420 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); | |
421 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
422 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
423 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
424 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); | |
425 | ||
426 | return 0; | |
427 | } | |
428 | ||
6b5fc39b JO |
429 | static int test__checkevent_pmu_name(struct perf_evlist *evlist) |
430 | { | |
0c21f736 | 431 | struct perf_evsel *evsel = perf_evlist__first(evlist); |
6b5fc39b | 432 | |
7a25b2d3 | 433 | /* cpu/config=1,name=krava/u */ |
6b5fc39b JO |
434 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); |
435 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | |
436 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); | |
22c8b843 | 437 | TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava")); |
6b5fc39b | 438 | |
7a25b2d3 | 439 | /* cpu/config=2/u" */ |
0c21f736 | 440 | evsel = perf_evsel__next(evsel); |
6b5fc39b JO |
441 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); |
442 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | |
443 | TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config); | |
7a25b2d3 | 444 | TEST_ASSERT_VAL("wrong name", |
ac2ba9f3 | 445 | !strcmp(perf_evsel__name(evsel), "cpu/config=2/u")); |
6b5fc39b JO |
446 | |
447 | return 0; | |
448 | } | |
449 | ||
3f3a2064 JO |
450 | static int test__checkevent_pmu_events(struct perf_evlist *evlist) |
451 | { | |
452 | struct perf_evsel *evsel; | |
453 | ||
454 | evsel = list_entry(evlist->entries.next, struct perf_evsel, node); | |
455 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); | |
456 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); | |
457 | TEST_ASSERT_VAL("wrong exclude_user", | |
458 | !evsel->attr.exclude_user); | |
459 | TEST_ASSERT_VAL("wrong exclude_kernel", | |
460 | 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 | ||
464 | return 0; | |
465 | } | |
466 | ||
4429392e JO |
467 | static int test__checkterms_simple(struct list_head *terms) |
468 | { | |
6cee6cd3 | 469 | struct parse_events_term *term; |
4429392e JO |
470 | |
471 | /* config=10 */ | |
6cee6cd3 | 472 | term = list_entry(terms->next, struct parse_events_term, list); |
4429392e JO |
473 | TEST_ASSERT_VAL("wrong type term", |
474 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG); | |
475 | TEST_ASSERT_VAL("wrong type val", | |
476 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | |
477 | TEST_ASSERT_VAL("wrong val", term->val.num == 10); | |
478 | TEST_ASSERT_VAL("wrong config", !term->config); | |
479 | ||
480 | /* config1 */ | |
6cee6cd3 | 481 | term = list_entry(term->list.next, struct parse_events_term, list); |
4429392e JO |
482 | TEST_ASSERT_VAL("wrong type term", |
483 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1); | |
484 | TEST_ASSERT_VAL("wrong type val", | |
485 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | |
486 | TEST_ASSERT_VAL("wrong val", term->val.num == 1); | |
487 | TEST_ASSERT_VAL("wrong config", !term->config); | |
488 | ||
489 | /* config2=3 */ | |
6cee6cd3 | 490 | term = list_entry(term->list.next, struct parse_events_term, list); |
4429392e JO |
491 | TEST_ASSERT_VAL("wrong type term", |
492 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2); | |
493 | TEST_ASSERT_VAL("wrong type val", | |
494 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | |
495 | TEST_ASSERT_VAL("wrong val", term->val.num == 3); | |
496 | TEST_ASSERT_VAL("wrong config", !term->config); | |
497 | ||
498 | /* umask=1*/ | |
6cee6cd3 | 499 | term = list_entry(term->list.next, struct parse_events_term, list); |
4429392e JO |
500 | TEST_ASSERT_VAL("wrong type term", |
501 | term->type_term == PARSE_EVENTS__TERM_TYPE_USER); | |
502 | TEST_ASSERT_VAL("wrong type val", | |
503 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); | |
504 | TEST_ASSERT_VAL("wrong val", term->val.num == 1); | |
505 | TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask")); | |
506 | ||
507 | return 0; | |
508 | } | |
509 | ||
905f5ee2 JO |
510 | static int test__group1(struct perf_evlist *evlist) |
511 | { | |
512 | struct perf_evsel *evsel, *leader; | |
513 | ||
514 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | |
8d7d8474 | 515 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); |
905f5ee2 JO |
516 | |
517 | /* instructions:k */ | |
0c21f736 | 518 | evsel = leader = perf_evlist__first(evlist); |
905f5ee2 JO |
519 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
520 | TEST_ASSERT_VAL("wrong config", | |
521 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); | |
522 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
523 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
524 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
525 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
526 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
527 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 528 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
8d7d8474 NK |
529 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
530 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
531 | |
532 | /* cycles:upp */ | |
0c21f736 | 533 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
534 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
535 | TEST_ASSERT_VAL("wrong config", | |
536 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
537 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
538 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
539 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
42be7398 JO |
540 | /* use of precise requires exclude_guest */ |
541 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
905f5ee2 JO |
542 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); |
543 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2); | |
544 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
8d7d8474 | 545 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
546 | |
547 | return 0; | |
548 | } | |
549 | ||
550 | static int test__group2(struct perf_evlist *evlist) | |
551 | { | |
552 | struct perf_evsel *evsel, *leader; | |
553 | ||
554 | TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); | |
8d7d8474 | 555 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); |
905f5ee2 JO |
556 | |
557 | /* faults + :ku modifier */ | |
0c21f736 | 558 | evsel = leader = perf_evlist__first(evlist); |
905f5ee2 JO |
559 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); |
560 | TEST_ASSERT_VAL("wrong config", | |
561 | PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config); | |
562 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
563 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
564 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
565 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
566 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
567 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 568 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
8d7d8474 NK |
569 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
570 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
571 | |
572 | /* cache-references + :u modifier */ | |
0c21f736 | 573 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
574 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
575 | TEST_ASSERT_VAL("wrong config", | |
576 | PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config); | |
577 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
578 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
579 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
5a30a99f | 580 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); |
905f5ee2 JO |
581 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); |
582 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
583 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
8d7d8474 | 584 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
585 | |
586 | /* cycles:k */ | |
0c21f736 | 587 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
588 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
589 | TEST_ASSERT_VAL("wrong config", | |
590 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
591 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
592 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
593 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
594 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
595 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
596 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 597 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
905f5ee2 JO |
598 | |
599 | return 0; | |
600 | } | |
601 | ||
1d037ca1 | 602 | static int test__group3(struct perf_evlist *evlist __maybe_unused) |
905f5ee2 JO |
603 | { |
604 | struct perf_evsel *evsel, *leader; | |
605 | ||
606 | TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries); | |
8d7d8474 | 607 | TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups); |
905f5ee2 JO |
608 | |
609 | /* group1 syscalls:sys_enter_open:H */ | |
0c21f736 | 610 | evsel = leader = perf_evlist__first(evlist); |
905f5ee2 JO |
611 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); |
612 | TEST_ASSERT_VAL("wrong sample_type", | |
613 | PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); | |
614 | TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); | |
615 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
616 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
617 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
618 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
619 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
620 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 621 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
905f5ee2 JO |
622 | TEST_ASSERT_VAL("wrong group name", |
623 | !strcmp(leader->group_name, "group1")); | |
8d7d8474 NK |
624 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
625 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
626 | |
627 | /* group1 cycles:kppp */ | |
0c21f736 | 628 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
629 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
630 | TEST_ASSERT_VAL("wrong config", | |
631 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
632 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
633 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
634 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
42be7398 JO |
635 | /* use of precise requires exclude_guest */ |
636 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
905f5ee2 JO |
637 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); |
638 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3); | |
639 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
640 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
8d7d8474 | 641 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
642 | |
643 | /* group2 cycles + G modifier */ | |
0c21f736 | 644 | evsel = leader = perf_evsel__next(evsel); |
905f5ee2 JO |
645 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
646 | TEST_ASSERT_VAL("wrong config", | |
647 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
648 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
649 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
650 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
651 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
652 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
653 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 654 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
905f5ee2 JO |
655 | TEST_ASSERT_VAL("wrong group name", |
656 | !strcmp(leader->group_name, "group2")); | |
8d7d8474 NK |
657 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
658 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
659 | |
660 | /* group2 1:3 + G modifier */ | |
0c21f736 | 661 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
662 | TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); |
663 | TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config); | |
664 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
665 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
666 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
667 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
668 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
669 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
670 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
8d7d8474 | 671 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
672 | |
673 | /* instructions:u */ | |
0c21f736 | 674 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
675 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
676 | TEST_ASSERT_VAL("wrong config", | |
677 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); | |
678 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
679 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
680 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
681 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
682 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
683 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 684 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
905f5ee2 JO |
685 | |
686 | return 0; | |
687 | } | |
688 | ||
1d037ca1 | 689 | static int test__group4(struct perf_evlist *evlist __maybe_unused) |
905f5ee2 JO |
690 | { |
691 | struct perf_evsel *evsel, *leader; | |
692 | ||
693 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | |
8d7d8474 | 694 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); |
905f5ee2 JO |
695 | |
696 | /* cycles:u + p */ | |
0c21f736 | 697 | evsel = leader = perf_evlist__first(evlist); |
905f5ee2 JO |
698 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
699 | TEST_ASSERT_VAL("wrong config", | |
700 | PERF_COUNT_HW_CPU_CYCLES == 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); | |
42be7398 JO |
704 | /* use of precise requires exclude_guest */ |
705 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
905f5ee2 JO |
706 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); |
707 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1); | |
708 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
823254ed | 709 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
8d7d8474 NK |
710 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
711 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
712 | |
713 | /* instructions:kp + p */ | |
0c21f736 | 714 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
715 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
716 | TEST_ASSERT_VAL("wrong config", | |
717 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); | |
718 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); | |
719 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
720 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
42be7398 JO |
721 | /* use of precise requires exclude_guest */ |
722 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
905f5ee2 JO |
723 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); |
724 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2); | |
725 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
8d7d8474 | 726 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
727 | |
728 | return 0; | |
729 | } | |
730 | ||
1d037ca1 | 731 | static int test__group5(struct perf_evlist *evlist __maybe_unused) |
905f5ee2 JO |
732 | { |
733 | struct perf_evsel *evsel, *leader; | |
734 | ||
735 | TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries); | |
8d7d8474 | 736 | TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups); |
905f5ee2 JO |
737 | |
738 | /* cycles + G */ | |
0c21f736 | 739 | evsel = leader = perf_evlist__first(evlist); |
905f5ee2 JO |
740 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
741 | TEST_ASSERT_VAL("wrong config", | |
742 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
743 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
744 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
745 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
746 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
747 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
748 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
749 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
823254ed | 750 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
8d7d8474 NK |
751 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
752 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
753 | |
754 | /* instructions + G */ | |
0c21f736 | 755 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
756 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
757 | TEST_ASSERT_VAL("wrong config", | |
758 | PERF_COUNT_HW_INSTRUCTIONS == 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); | |
762 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
763 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
764 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
765 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
8d7d8474 | 766 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
767 | |
768 | /* cycles:G */ | |
0c21f736 | 769 | evsel = leader = perf_evsel__next(evsel); |
905f5ee2 JO |
770 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
771 | TEST_ASSERT_VAL("wrong config", | |
772 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
773 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
774 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
775 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
776 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
777 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
778 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
779 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
823254ed | 780 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
8d7d8474 NK |
781 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); |
782 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
905f5ee2 JO |
783 | |
784 | /* instructions:G */ | |
0c21f736 | 785 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
786 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
787 | TEST_ASSERT_VAL("wrong config", | |
788 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); | |
789 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
790 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
791 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
792 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
793 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
794 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
795 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
8d7d8474 | 796 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); |
905f5ee2 JO |
797 | |
798 | /* cycles */ | |
0c21f736 | 799 | evsel = perf_evsel__next(evsel); |
905f5ee2 JO |
800 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
801 | TEST_ASSERT_VAL("wrong config", | |
802 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
803 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
804 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
805 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
806 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
807 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
808 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
823254ed | 809 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); |
905f5ee2 JO |
810 | |
811 | return 0; | |
812 | } | |
813 | ||
5a30a99f JO |
814 | static int test__group_gh1(struct perf_evlist *evlist) |
815 | { | |
816 | struct perf_evsel *evsel, *leader; | |
817 | ||
818 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | |
819 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); | |
820 | ||
821 | /* cycles + :H group modifier */ | |
822 | evsel = leader = perf_evlist__first(evlist); | |
823 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
824 | TEST_ASSERT_VAL("wrong config", | |
825 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
826 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
827 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
828 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
829 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
830 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
831 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
832 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
833 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); | |
834 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); | |
835 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
836 | ||
837 | /* cache-misses:G + :H group modifier */ | |
838 | evsel = perf_evsel__next(evsel); | |
839 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
840 | TEST_ASSERT_VAL("wrong config", | |
841 | PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); | |
842 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
843 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
844 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
845 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
846 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
847 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
848 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
849 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); | |
850 | ||
851 | return 0; | |
852 | } | |
853 | ||
854 | static int test__group_gh2(struct perf_evlist *evlist) | |
855 | { | |
856 | struct perf_evsel *evsel, *leader; | |
857 | ||
858 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | |
859 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); | |
860 | ||
861 | /* cycles + :G group modifier */ | |
862 | evsel = leader = perf_evlist__first(evlist); | |
863 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
864 | TEST_ASSERT_VAL("wrong config", | |
865 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
866 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
867 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
868 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
869 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
870 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
871 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
872 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
873 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); | |
874 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); | |
875 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
876 | ||
877 | /* cache-misses:H + :G group modifier */ | |
878 | evsel = perf_evsel__next(evsel); | |
879 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
880 | TEST_ASSERT_VAL("wrong config", | |
881 | PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); | |
882 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
883 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); | |
884 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); | |
885 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
886 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
887 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
888 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
889 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); | |
890 | ||
891 | return 0; | |
892 | } | |
893 | ||
894 | static int test__group_gh3(struct perf_evlist *evlist) | |
895 | { | |
896 | struct perf_evsel *evsel, *leader; | |
897 | ||
898 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | |
899 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); | |
900 | ||
901 | /* cycles:G + :u group modifier */ | |
902 | evsel = leader = perf_evlist__first(evlist); | |
903 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
904 | TEST_ASSERT_VAL("wrong config", | |
905 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
906 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
907 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
908 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
909 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
910 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
911 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
912 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
913 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); | |
914 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); | |
915 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
916 | ||
917 | /* cache-misses:H + :u group modifier */ | |
918 | evsel = perf_evsel__next(evsel); | |
919 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
920 | TEST_ASSERT_VAL("wrong config", | |
921 | PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); | |
922 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
923 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
924 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
925 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); | |
926 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); | |
927 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
928 | TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); | |
929 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); | |
930 | ||
931 | return 0; | |
932 | } | |
933 | ||
934 | static int test__group_gh4(struct perf_evlist *evlist) | |
935 | { | |
936 | struct perf_evsel *evsel, *leader; | |
937 | ||
938 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); | |
939 | TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); | |
940 | ||
941 | /* cycles:G + :uG group modifier */ | |
942 | evsel = leader = perf_evlist__first(evlist); | |
943 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
944 | TEST_ASSERT_VAL("wrong config", | |
945 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); | |
946 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); | |
947 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); | |
948 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); | |
949 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); | |
950 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); | |
951 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); | |
952 | TEST_ASSERT_VAL("wrong group name", !evsel->group_name); | |
953 | TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); | |
954 | TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); | |
955 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); | |
956 | ||
957 | /* cache-misses:H + :uG group modifier */ | |
958 | evsel = perf_evsel__next(evsel); | |
959 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); | |
960 | TEST_ASSERT_VAL("wrong config", | |
961 | PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader); | |
969 | TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); | |
970 | ||
971 | return 0; | |
972 | } | |
973 | ||
82ce75d9 JO |
974 | static int count_tracepoints(void) |
975 | { | |
976 | char events_path[PATH_MAX]; | |
977 | struct dirent *events_ent; | |
978 | DIR *events_dir; | |
979 | int cnt = 0; | |
980 | ||
981 | scnprintf(events_path, PATH_MAX, "%s/tracing/events", | |
982 | debugfs_find_mountpoint()); | |
983 | ||
984 | events_dir = opendir(events_path); | |
985 | ||
986 | TEST_ASSERT_VAL("Can't open events dir", events_dir); | |
987 | ||
988 | while ((events_ent = readdir(events_dir))) { | |
989 | char sys_path[PATH_MAX]; | |
990 | struct dirent *sys_ent; | |
991 | DIR *sys_dir; | |
992 | ||
993 | if (!strcmp(events_ent->d_name, ".") | |
994 | || !strcmp(events_ent->d_name, "..") | |
995 | || !strcmp(events_ent->d_name, "enable") | |
996 | || !strcmp(events_ent->d_name, "header_event") | |
997 | || !strcmp(events_ent->d_name, "header_page")) | |
998 | continue; | |
999 | ||
1000 | scnprintf(sys_path, PATH_MAX, "%s/%s", | |
1001 | events_path, events_ent->d_name); | |
1002 | ||
1003 | sys_dir = opendir(sys_path); | |
1004 | TEST_ASSERT_VAL("Can't open sys dir", sys_dir); | |
1005 | ||
1006 | while ((sys_ent = readdir(sys_dir))) { | |
1007 | if (!strcmp(sys_ent->d_name, ".") | |
1008 | || !strcmp(sys_ent->d_name, "..") | |
1009 | || !strcmp(sys_ent->d_name, "enable") | |
1010 | || !strcmp(sys_ent->d_name, "filter")) | |
1011 | continue; | |
1012 | ||
1013 | cnt++; | |
1014 | } | |
1015 | ||
1016 | closedir(sys_dir); | |
1017 | } | |
1018 | ||
1019 | closedir(events_dir); | |
1020 | return cnt; | |
1021 | } | |
1022 | ||
1023 | static int test__all_tracepoints(struct perf_evlist *evlist) | |
1024 | { | |
1025 | TEST_ASSERT_VAL("wrong events count", | |
1026 | count_tracepoints() == evlist->nr_entries); | |
1027 | ||
1028 | return test__checkevent_tracepoint_multi(evlist); | |
1029 | } | |
1030 | ||
23b6339b | 1031 | struct evlist_test { |
f50246e2 JO |
1032 | const char *name; |
1033 | __u32 type; | |
1034 | int (*check)(struct perf_evlist *evlist); | |
1035 | }; | |
1036 | ||
23b6339b | 1037 | static struct evlist_test test__events[] = { |
f50246e2 JO |
1038 | [0] = { |
1039 | .name = "syscalls:sys_enter_open", | |
1040 | .check = test__checkevent_tracepoint, | |
1041 | }, | |
1042 | [1] = { | |
1043 | .name = "syscalls:*", | |
1044 | .check = test__checkevent_tracepoint_multi, | |
1045 | }, | |
1046 | [2] = { | |
1047 | .name = "r1a", | |
1048 | .check = test__checkevent_raw, | |
1049 | }, | |
1050 | [3] = { | |
1051 | .name = "1:1", | |
1052 | .check = test__checkevent_numeric, | |
1053 | }, | |
1054 | [4] = { | |
1055 | .name = "instructions", | |
1056 | .check = test__checkevent_symbolic_name, | |
1057 | }, | |
1058 | [5] = { | |
1059 | .name = "cycles/period=100000,config2/", | |
1060 | .check = test__checkevent_symbolic_name_config, | |
1061 | }, | |
1062 | [6] = { | |
1063 | .name = "faults", | |
1064 | .check = test__checkevent_symbolic_alias, | |
1065 | }, | |
1066 | [7] = { | |
1067 | .name = "L1-dcache-load-miss", | |
1068 | .check = test__checkevent_genhw, | |
1069 | }, | |
1070 | [8] = { | |
1071 | .name = "mem:0", | |
1072 | .check = test__checkevent_breakpoint, | |
1073 | }, | |
1074 | [9] = { | |
1075 | .name = "mem:0:x", | |
1076 | .check = test__checkevent_breakpoint_x, | |
1077 | }, | |
1078 | [10] = { | |
1079 | .name = "mem:0:r", | |
1080 | .check = test__checkevent_breakpoint_r, | |
1081 | }, | |
1082 | [11] = { | |
1083 | .name = "mem:0:w", | |
1084 | .check = test__checkevent_breakpoint_w, | |
1085 | }, | |
1086 | [12] = { | |
1087 | .name = "syscalls:sys_enter_open:k", | |
1088 | .check = test__checkevent_tracepoint_modifier, | |
1089 | }, | |
1090 | [13] = { | |
1091 | .name = "syscalls:*:u", | |
1092 | .check = test__checkevent_tracepoint_multi_modifier, | |
1093 | }, | |
1094 | [14] = { | |
1095 | .name = "r1a:kp", | |
1096 | .check = test__checkevent_raw_modifier, | |
1097 | }, | |
1098 | [15] = { | |
1099 | .name = "1:1:hp", | |
1100 | .check = test__checkevent_numeric_modifier, | |
1101 | }, | |
1102 | [16] = { | |
1103 | .name = "instructions:h", | |
1104 | .check = test__checkevent_symbolic_name_modifier, | |
1105 | }, | |
1106 | [17] = { | |
1107 | .name = "faults:u", | |
1108 | .check = test__checkevent_symbolic_alias_modifier, | |
1109 | }, | |
1110 | [18] = { | |
1111 | .name = "L1-dcache-load-miss:kp", | |
1112 | .check = test__checkevent_genhw_modifier, | |
1113 | }, | |
1114 | [19] = { | |
1115 | .name = "mem:0:u", | |
1116 | .check = test__checkevent_breakpoint_modifier, | |
1117 | }, | |
1118 | [20] = { | |
1119 | .name = "mem:0:x:k", | |
1120 | .check = test__checkevent_breakpoint_x_modifier, | |
1121 | }, | |
1122 | [21] = { | |
1123 | .name = "mem:0:r:hp", | |
1124 | .check = test__checkevent_breakpoint_r_modifier, | |
1125 | }, | |
1126 | [22] = { | |
1127 | .name = "mem:0:w:up", | |
1128 | .check = test__checkevent_breakpoint_w_modifier, | |
1129 | }, | |
1130 | [23] = { | |
1131 | .name = "r1,syscalls:sys_enter_open:k,1:1:hp", | |
1132 | .check = test__checkevent_list, | |
1133 | }, | |
1134 | [24] = { | |
1135 | .name = "instructions:G", | |
1136 | .check = test__checkevent_exclude_host_modifier, | |
1137 | }, | |
1138 | [25] = { | |
1139 | .name = "instructions:H", | |
1140 | .check = test__checkevent_exclude_guest_modifier, | |
1141 | }, | |
7582732f JO |
1142 | [26] = { |
1143 | .name = "mem:0:rw", | |
1144 | .check = test__checkevent_breakpoint_rw, | |
1145 | }, | |
1146 | [27] = { | |
1147 | .name = "mem:0:rw:kp", | |
1148 | .check = test__checkevent_breakpoint_rw_modifier, | |
1149 | }, | |
905f5ee2 JO |
1150 | [28] = { |
1151 | .name = "{instructions:k,cycles:upp}", | |
1152 | .check = test__group1, | |
1153 | }, | |
1154 | [29] = { | |
1155 | .name = "{faults:k,cache-references}:u,cycles:k", | |
1156 | .check = test__group2, | |
1157 | }, | |
1158 | [30] = { | |
1159 | .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u", | |
1160 | .check = test__group3, | |
1161 | }, | |
1162 | [31] = { | |
1163 | .name = "{cycles:u,instructions:kp}:p", | |
1164 | .check = test__group4, | |
1165 | }, | |
1166 | [32] = { | |
1167 | .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles", | |
1168 | .check = test__group5, | |
1169 | }, | |
82ce75d9 JO |
1170 | [33] = { |
1171 | .name = "*:*", | |
1172 | .check = test__all_tracepoints, | |
1173 | }, | |
5a30a99f JO |
1174 | [34] = { |
1175 | .name = "{cycles,cache-misses:G}:H", | |
1176 | .check = test__group_gh1, | |
1177 | }, | |
1178 | [35] = { | |
1179 | .name = "{cycles,cache-misses:H}:G", | |
1180 | .check = test__group_gh2, | |
1181 | }, | |
1182 | [36] = { | |
1183 | .name = "{cycles:G,cache-misses:H}:u", | |
1184 | .check = test__group_gh3, | |
1185 | }, | |
1186 | [37] = { | |
1187 | .name = "{cycles:G,cache-misses:H}:uG", | |
1188 | .check = test__group_gh4, | |
1189 | }, | |
f50246e2 JO |
1190 | }; |
1191 | ||
23b6339b | 1192 | static struct evlist_test test__events_pmu[] = { |
f50246e2 JO |
1193 | [0] = { |
1194 | .name = "cpu/config=10,config1,config2=3,period=1000/u", | |
1195 | .check = test__checkevent_pmu, | |
1196 | }, | |
6b5fc39b JO |
1197 | [1] = { |
1198 | .name = "cpu/config=1,name=krava/u,cpu/config=2/u", | |
1199 | .check = test__checkevent_pmu_name, | |
1200 | }, | |
f50246e2 JO |
1201 | }; |
1202 | ||
23b6339b | 1203 | struct terms_test { |
4429392e JO |
1204 | const char *str; |
1205 | __u32 type; | |
1206 | int (*check)(struct list_head *terms); | |
1207 | }; | |
1208 | ||
23b6339b | 1209 | static struct terms_test test__terms[] = { |
4429392e JO |
1210 | [0] = { |
1211 | .str = "config=10,config1,config2=3,umask=1", | |
1212 | .check = test__checkterms_simple, | |
1213 | }, | |
1214 | }; | |
1215 | ||
23b6339b | 1216 | static int test_event(struct evlist_test *e) |
f50246e2 JO |
1217 | { |
1218 | struct perf_evlist *evlist; | |
1219 | int ret; | |
1220 | ||
1221 | evlist = perf_evlist__new(NULL, NULL); | |
1222 | if (evlist == NULL) | |
1223 | return -ENOMEM; | |
1224 | ||
d8f7bbc9 | 1225 | ret = parse_events(evlist, e->name); |
f50246e2 JO |
1226 | if (ret) { |
1227 | pr_debug("failed to parse event '%s', err %d\n", | |
1228 | e->name, ret); | |
1229 | return ret; | |
1230 | } | |
1231 | ||
1232 | ret = e->check(evlist); | |
1233 | perf_evlist__delete(evlist); | |
1234 | ||
1235 | return ret; | |
1236 | } | |
1237 | ||
23b6339b | 1238 | static int test_events(struct evlist_test *events, unsigned cnt) |
f50246e2 | 1239 | { |
9bfbbc6d | 1240 | int ret1, ret2 = 0; |
f50246e2 JO |
1241 | unsigned i; |
1242 | ||
1243 | for (i = 0; i < cnt; i++) { | |
23b6339b | 1244 | struct evlist_test *e = &events[i]; |
f50246e2 JO |
1245 | |
1246 | pr_debug("running test %d '%s'\n", i, e->name); | |
9bfbbc6d RR |
1247 | ret1 = test_event(e); |
1248 | if (ret1) | |
1249 | ret2 = ret1; | |
4429392e JO |
1250 | } |
1251 | ||
9bfbbc6d | 1252 | return ret2; |
4429392e JO |
1253 | } |
1254 | ||
23b6339b | 1255 | static int test_term(struct terms_test *t) |
4429392e JO |
1256 | { |
1257 | struct list_head *terms; | |
1258 | int ret; | |
1259 | ||
1260 | terms = malloc(sizeof(*terms)); | |
1261 | if (!terms) | |
1262 | return -ENOMEM; | |
1263 | ||
1264 | INIT_LIST_HEAD(terms); | |
1265 | ||
1266 | ret = parse_events_terms(terms, t->str); | |
1267 | if (ret) { | |
1268 | pr_debug("failed to parse terms '%s', err %d\n", | |
1269 | t->str , ret); | |
1270 | return ret; | |
1271 | } | |
1272 | ||
1273 | ret = t->check(terms); | |
1274 | parse_events__free_terms(terms); | |
1275 | ||
1276 | return ret; | |
1277 | } | |
1278 | ||
23b6339b | 1279 | static int test_terms(struct terms_test *terms, unsigned cnt) |
4429392e JO |
1280 | { |
1281 | int ret = 0; | |
1282 | unsigned i; | |
1283 | ||
1284 | for (i = 0; i < cnt; i++) { | |
23b6339b | 1285 | struct terms_test *t = &terms[i]; |
4429392e JO |
1286 | |
1287 | pr_debug("running test %d '%s'\n", i, t->str); | |
1288 | ret = test_term(t); | |
f50246e2 JO |
1289 | if (ret) |
1290 | break; | |
1291 | } | |
1292 | ||
1293 | return ret; | |
1294 | } | |
1295 | ||
1296 | static int test_pmu(void) | |
1297 | { | |
1298 | struct stat st; | |
1299 | char path[PATH_MAX]; | |
1300 | int ret; | |
1301 | ||
1302 | snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/", | |
1303 | sysfs_find_mountpoint()); | |
1304 | ||
1305 | ret = stat(path, &st); | |
1306 | if (ret) | |
3fd44cd4 | 1307 | pr_debug("omitting PMU cpu tests\n"); |
f50246e2 JO |
1308 | return !ret; |
1309 | } | |
1310 | ||
3f3a2064 JO |
1311 | static int test_pmu_events(void) |
1312 | { | |
1313 | struct stat st; | |
1314 | char path[PATH_MAX]; | |
1315 | struct dirent *ent; | |
1316 | DIR *dir; | |
1317 | int ret; | |
1318 | ||
1319 | snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/", | |
1320 | sysfs_find_mountpoint()); | |
1321 | ||
1322 | ret = stat(path, &st); | |
1323 | if (ret) { | |
1324 | pr_debug("ommiting PMU cpu events tests\n"); | |
1325 | return 0; | |
1326 | } | |
1327 | ||
1328 | dir = opendir(path); | |
1329 | if (!dir) { | |
1330 | pr_debug("can't open pmu event dir"); | |
1331 | return -1; | |
1332 | } | |
1333 | ||
1334 | while (!ret && (ent = readdir(dir))) { | |
1335 | #define MAX_NAME 100 | |
23b6339b | 1336 | struct evlist_test e; |
3f3a2064 JO |
1337 | char name[MAX_NAME]; |
1338 | ||
1339 | if (!strcmp(ent->d_name, ".") || | |
1340 | !strcmp(ent->d_name, "..")) | |
1341 | continue; | |
1342 | ||
1343 | snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name); | |
1344 | ||
1345 | e.name = name; | |
1346 | e.check = test__checkevent_pmu_events; | |
1347 | ||
1348 | ret = test_event(&e); | |
1349 | #undef MAX_NAME | |
1350 | } | |
1351 | ||
1352 | closedir(dir); | |
1353 | return ret; | |
1354 | } | |
1355 | ||
c81251e8 | 1356 | int test__parse_events(void) |
f50246e2 | 1357 | { |
9bfbbc6d | 1358 | int ret1, ret2 = 0; |
f50246e2 | 1359 | |
ebf124ff JO |
1360 | #define TEST_EVENTS(tests) \ |
1361 | do { \ | |
9bfbbc6d RR |
1362 | ret1 = test_events(tests, ARRAY_SIZE(tests)); \ |
1363 | if (!ret2) \ | |
1364 | ret2 = ret1; \ | |
ebf124ff | 1365 | } while (0) |
4429392e | 1366 | |
ebf124ff | 1367 | TEST_EVENTS(test__events); |
4429392e | 1368 | |
ebf124ff JO |
1369 | if (test_pmu()) |
1370 | TEST_EVENTS(test__events_pmu); | |
f50246e2 | 1371 | |
3f3a2064 JO |
1372 | if (test_pmu()) { |
1373 | int ret = test_pmu_events(); | |
1374 | if (ret) | |
1375 | return ret; | |
1376 | } | |
1377 | ||
9bfbbc6d RR |
1378 | ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms)); |
1379 | if (!ret2) | |
1380 | ret2 = ret1; | |
1381 | ||
1382 | return ret2; | |
f50246e2 | 1383 | } |