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