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