Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 1 | |
| 2 | #include "parse-events.h" |
| 3 | #include "evsel.h" |
| 4 | #include "evlist.h" |
| 5 | #include "sysfs.h" |
| 6 | #include "../../../include/linux/hw_breakpoint.h" |
| 7 | |
| 8 | #define TEST_ASSERT_VAL(text, cond) \ |
| 9 | do { \ |
| 10 | if (!(cond)) { \ |
| 11 | pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \ |
| 12 | return -1; \ |
| 13 | } \ |
| 14 | } while (0) |
| 15 | |
| 16 | static int test__checkevent_tracepoint(struct perf_evlist *evlist) |
| 17 | { |
| 18 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 19 | struct perf_evsel, node); |
| 20 | |
| 21 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 22 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); |
| 23 | TEST_ASSERT_VAL("wrong sample_type", |
| 24 | (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) == |
| 25 | evsel->attr.sample_type); |
| 26 | TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist) |
| 31 | { |
| 32 | struct perf_evsel *evsel; |
| 33 | |
| 34 | TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); |
| 35 | |
| 36 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 37 | TEST_ASSERT_VAL("wrong type", |
| 38 | PERF_TYPE_TRACEPOINT == evsel->attr.type); |
| 39 | TEST_ASSERT_VAL("wrong sample_type", |
| 40 | (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) |
| 41 | == evsel->attr.sample_type); |
| 42 | TEST_ASSERT_VAL("wrong sample_period", |
| 43 | 1 == evsel->attr.sample_period); |
| 44 | } |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static int test__checkevent_raw(struct perf_evlist *evlist) |
| 49 | { |
| 50 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 51 | struct perf_evsel, node); |
| 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 | { |
| 61 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 62 | struct perf_evsel, node); |
| 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 | { |
| 72 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 73 | struct perf_evsel, node); |
| 74 | |
| 75 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 76 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
| 77 | TEST_ASSERT_VAL("wrong config", |
| 78 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist) |
| 83 | { |
| 84 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 85 | struct perf_evsel, node); |
| 86 | |
| 87 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 88 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
| 89 | TEST_ASSERT_VAL("wrong config", |
| 90 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); |
| 91 | TEST_ASSERT_VAL("wrong period", |
| 92 | 100000 == evsel->attr.sample_period); |
| 93 | TEST_ASSERT_VAL("wrong config1", |
| 94 | 0 == evsel->attr.config1); |
| 95 | TEST_ASSERT_VAL("wrong config2", |
| 96 | 1 == evsel->attr.config2); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int test__checkevent_symbolic_alias(struct perf_evlist *evlist) |
| 101 | { |
| 102 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 103 | struct perf_evsel, node); |
| 104 | |
| 105 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 106 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); |
| 107 | TEST_ASSERT_VAL("wrong config", |
| 108 | PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config); |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static int test__checkevent_genhw(struct perf_evlist *evlist) |
| 113 | { |
| 114 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 115 | struct perf_evsel, node); |
| 116 | |
| 117 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 118 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type); |
| 119 | TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static int test__checkevent_breakpoint(struct perf_evlist *evlist) |
| 124 | { |
| 125 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 126 | struct perf_evsel, node); |
| 127 | |
| 128 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 129 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 130 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 131 | TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == |
| 132 | evsel->attr.bp_type); |
| 133 | TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 == |
| 134 | evsel->attr.bp_len); |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int test__checkevent_breakpoint_x(struct perf_evlist *evlist) |
| 139 | { |
| 140 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 141 | struct perf_evsel, node); |
| 142 | |
| 143 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 144 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 145 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 146 | TEST_ASSERT_VAL("wrong bp_type", |
| 147 | HW_BREAKPOINT_X == evsel->attr.bp_type); |
| 148 | TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len); |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int test__checkevent_breakpoint_r(struct perf_evlist *evlist) |
| 153 | { |
| 154 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 155 | struct perf_evsel, node); |
| 156 | |
| 157 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 158 | TEST_ASSERT_VAL("wrong type", |
| 159 | PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 160 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 161 | TEST_ASSERT_VAL("wrong bp_type", |
| 162 | HW_BREAKPOINT_R == evsel->attr.bp_type); |
| 163 | TEST_ASSERT_VAL("wrong bp_len", |
| 164 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int test__checkevent_breakpoint_w(struct perf_evlist *evlist) |
| 169 | { |
| 170 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 171 | struct perf_evsel, node); |
| 172 | |
| 173 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 174 | TEST_ASSERT_VAL("wrong type", |
| 175 | PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 176 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 177 | TEST_ASSERT_VAL("wrong bp_type", |
| 178 | HW_BREAKPOINT_W == evsel->attr.bp_type); |
| 179 | TEST_ASSERT_VAL("wrong bp_len", |
| 180 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); |
| 181 | return 0; |
| 182 | } |
| 183 | |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame^] | 184 | static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist) |
| 185 | { |
| 186 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 187 | struct perf_evsel, node); |
| 188 | |
| 189 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 190 | TEST_ASSERT_VAL("wrong type", |
| 191 | PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 192 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 193 | TEST_ASSERT_VAL("wrong bp_type", |
| 194 | (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type); |
| 195 | TEST_ASSERT_VAL("wrong bp_len", |
| 196 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); |
| 197 | return 0; |
| 198 | } |
| 199 | |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 200 | static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist) |
| 201 | { |
| 202 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 203 | struct perf_evsel, node); |
| 204 | |
| 205 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 206 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 207 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 208 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 209 | |
| 210 | return test__checkevent_tracepoint(evlist); |
| 211 | } |
| 212 | |
| 213 | static int |
| 214 | test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist) |
| 215 | { |
| 216 | struct perf_evsel *evsel; |
| 217 | |
| 218 | TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); |
| 219 | |
| 220 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 221 | TEST_ASSERT_VAL("wrong exclude_user", |
| 222 | !evsel->attr.exclude_user); |
| 223 | TEST_ASSERT_VAL("wrong exclude_kernel", |
| 224 | evsel->attr.exclude_kernel); |
| 225 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 226 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 227 | } |
| 228 | |
| 229 | return test__checkevent_tracepoint_multi(evlist); |
| 230 | } |
| 231 | |
| 232 | static int test__checkevent_raw_modifier(struct perf_evlist *evlist) |
| 233 | { |
| 234 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 235 | struct perf_evsel, node); |
| 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_raw(evlist); |
| 243 | } |
| 244 | |
| 245 | static int test__checkevent_numeric_modifier(struct perf_evlist *evlist) |
| 246 | { |
| 247 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 248 | struct perf_evsel, node); |
| 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_numeric(evlist); |
| 256 | } |
| 257 | |
| 258 | static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist) |
| 259 | { |
| 260 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 261 | struct perf_evsel, node); |
| 262 | |
| 263 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 264 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 265 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
| 266 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 267 | |
| 268 | return test__checkevent_symbolic_name(evlist); |
| 269 | } |
| 270 | |
| 271 | static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist) |
| 272 | { |
| 273 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 274 | struct perf_evsel, node); |
| 275 | |
| 276 | TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); |
| 277 | TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); |
| 278 | |
| 279 | return test__checkevent_symbolic_name(evlist); |
| 280 | } |
| 281 | |
| 282 | static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist) |
| 283 | { |
| 284 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 285 | struct perf_evsel, node); |
| 286 | |
| 287 | TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); |
| 288 | TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); |
| 289 | |
| 290 | return test__checkevent_symbolic_name(evlist); |
| 291 | } |
| 292 | |
| 293 | static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist) |
| 294 | { |
| 295 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 296 | struct perf_evsel, node); |
| 297 | |
| 298 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); |
| 299 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 300 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 301 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 302 | |
| 303 | return test__checkevent_symbolic_alias(evlist); |
| 304 | } |
| 305 | |
| 306 | static int test__checkevent_genhw_modifier(struct perf_evlist *evlist) |
| 307 | { |
| 308 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 309 | struct perf_evsel, node); |
| 310 | |
| 311 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 312 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 313 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 314 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 315 | |
| 316 | return test__checkevent_genhw(evlist); |
| 317 | } |
| 318 | |
| 319 | static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist) |
| 320 | { |
| 321 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 322 | struct perf_evsel, node); |
| 323 | |
| 324 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); |
| 325 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 326 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 327 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 328 | |
| 329 | return test__checkevent_breakpoint(evlist); |
| 330 | } |
| 331 | |
| 332 | static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist) |
| 333 | { |
| 334 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 335 | struct perf_evsel, node); |
| 336 | |
| 337 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 338 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 339 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 340 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 341 | |
| 342 | return test__checkevent_breakpoint_x(evlist); |
| 343 | } |
| 344 | |
| 345 | static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist) |
| 346 | { |
| 347 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 348 | struct perf_evsel, node); |
| 349 | |
| 350 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 351 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 352 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
| 353 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 354 | |
| 355 | return test__checkevent_breakpoint_r(evlist); |
| 356 | } |
| 357 | |
| 358 | static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist) |
| 359 | { |
| 360 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 361 | struct perf_evsel, node); |
| 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); |
| 367 | |
| 368 | return test__checkevent_breakpoint_w(evlist); |
| 369 | } |
| 370 | |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame^] | 371 | static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist) |
| 372 | { |
| 373 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 374 | struct perf_evsel, node); |
| 375 | |
| 376 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 377 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 378 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 379 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 380 | |
| 381 | return test__checkevent_breakpoint_rw(evlist); |
| 382 | } |
| 383 | |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 384 | static int test__checkevent_pmu(struct perf_evlist *evlist) |
| 385 | { |
| 386 | |
| 387 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 388 | struct perf_evsel, node); |
| 389 | |
| 390 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 391 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
| 392 | TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config); |
| 393 | TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1); |
| 394 | TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2); |
| 395 | TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period); |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static int test__checkevent_list(struct perf_evlist *evlist) |
| 401 | { |
| 402 | struct perf_evsel *evsel; |
| 403 | |
| 404 | TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); |
| 405 | |
| 406 | /* r1 */ |
| 407 | evsel = list_entry(evlist->entries.next, struct perf_evsel, node); |
| 408 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
| 409 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); |
| 410 | TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1); |
| 411 | TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2); |
| 412 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); |
| 413 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 414 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
| 415 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 416 | |
| 417 | /* syscalls:sys_enter_open:k */ |
| 418 | evsel = list_entry(evsel->node.next, struct perf_evsel, node); |
| 419 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); |
| 420 | TEST_ASSERT_VAL("wrong sample_type", |
| 421 | (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) == |
| 422 | evsel->attr.sample_type); |
| 423 | TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); |
| 424 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 425 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 426 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 427 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 428 | |
| 429 | /* 1:1:hp */ |
| 430 | evsel = list_entry(evsel->node.next, struct perf_evsel, node); |
| 431 | TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); |
| 432 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); |
| 433 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 434 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 435 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
| 436 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 441 | static int test__checkevent_pmu_name(struct perf_evlist *evlist) |
| 442 | { |
| 443 | struct perf_evsel *evsel; |
| 444 | |
Jiri Olsa | 7a25b2d | 2012-06-21 12:25:16 +0200 | [diff] [blame] | 445 | /* cpu/config=1,name=krava/u */ |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 446 | evsel = list_entry(evlist->entries.next, struct perf_evsel, node); |
| 447 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); |
| 448 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
| 449 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); |
Arnaldo Carvalho de Melo | 22c8b84 | 2012-06-12 13:55:13 -0300 | [diff] [blame] | 450 | TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava")); |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 451 | |
Jiri Olsa | 7a25b2d | 2012-06-21 12:25:16 +0200 | [diff] [blame] | 452 | /* cpu/config=2/u" */ |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 453 | evsel = list_entry(evsel->node.next, struct perf_evsel, node); |
| 454 | TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); |
| 455 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
| 456 | TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config); |
Jiri Olsa | 7a25b2d | 2012-06-21 12:25:16 +0200 | [diff] [blame] | 457 | TEST_ASSERT_VAL("wrong name", |
| 458 | !strcmp(perf_evsel__name(evsel), "raw 0x2:u")); |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Jiri Olsa | 4429392 | 2012-06-15 14:31:42 +0800 | [diff] [blame] | 463 | static int test__checkterms_simple(struct list_head *terms) |
| 464 | { |
| 465 | struct parse_events__term *term; |
| 466 | |
| 467 | /* config=10 */ |
| 468 | term = list_entry(terms->next, struct parse_events__term, list); |
| 469 | TEST_ASSERT_VAL("wrong type term", |
| 470 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG); |
| 471 | TEST_ASSERT_VAL("wrong type val", |
| 472 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); |
| 473 | TEST_ASSERT_VAL("wrong val", term->val.num == 10); |
| 474 | TEST_ASSERT_VAL("wrong config", !term->config); |
| 475 | |
| 476 | /* config1 */ |
| 477 | term = list_entry(term->list.next, struct parse_events__term, list); |
| 478 | TEST_ASSERT_VAL("wrong type term", |
| 479 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1); |
| 480 | TEST_ASSERT_VAL("wrong type val", |
| 481 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); |
| 482 | TEST_ASSERT_VAL("wrong val", term->val.num == 1); |
| 483 | TEST_ASSERT_VAL("wrong config", !term->config); |
| 484 | |
| 485 | /* config2=3 */ |
| 486 | term = list_entry(term->list.next, struct parse_events__term, list); |
| 487 | TEST_ASSERT_VAL("wrong type term", |
| 488 | term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2); |
| 489 | TEST_ASSERT_VAL("wrong type val", |
| 490 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); |
| 491 | TEST_ASSERT_VAL("wrong val", term->val.num == 3); |
| 492 | TEST_ASSERT_VAL("wrong config", !term->config); |
| 493 | |
| 494 | /* umask=1*/ |
| 495 | term = list_entry(term->list.next, struct parse_events__term, list); |
| 496 | TEST_ASSERT_VAL("wrong type term", |
| 497 | term->type_term == PARSE_EVENTS__TERM_TYPE_USER); |
| 498 | TEST_ASSERT_VAL("wrong type val", |
| 499 | term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); |
| 500 | TEST_ASSERT_VAL("wrong val", term->val.num == 1); |
| 501 | TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask")); |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 506 | struct test__event_st { |
| 507 | const char *name; |
| 508 | __u32 type; |
| 509 | int (*check)(struct perf_evlist *evlist); |
| 510 | }; |
| 511 | |
| 512 | static struct test__event_st test__events[] = { |
| 513 | [0] = { |
| 514 | .name = "syscalls:sys_enter_open", |
| 515 | .check = test__checkevent_tracepoint, |
| 516 | }, |
| 517 | [1] = { |
| 518 | .name = "syscalls:*", |
| 519 | .check = test__checkevent_tracepoint_multi, |
| 520 | }, |
| 521 | [2] = { |
| 522 | .name = "r1a", |
| 523 | .check = test__checkevent_raw, |
| 524 | }, |
| 525 | [3] = { |
| 526 | .name = "1:1", |
| 527 | .check = test__checkevent_numeric, |
| 528 | }, |
| 529 | [4] = { |
| 530 | .name = "instructions", |
| 531 | .check = test__checkevent_symbolic_name, |
| 532 | }, |
| 533 | [5] = { |
| 534 | .name = "cycles/period=100000,config2/", |
| 535 | .check = test__checkevent_symbolic_name_config, |
| 536 | }, |
| 537 | [6] = { |
| 538 | .name = "faults", |
| 539 | .check = test__checkevent_symbolic_alias, |
| 540 | }, |
| 541 | [7] = { |
| 542 | .name = "L1-dcache-load-miss", |
| 543 | .check = test__checkevent_genhw, |
| 544 | }, |
| 545 | [8] = { |
| 546 | .name = "mem:0", |
| 547 | .check = test__checkevent_breakpoint, |
| 548 | }, |
| 549 | [9] = { |
| 550 | .name = "mem:0:x", |
| 551 | .check = test__checkevent_breakpoint_x, |
| 552 | }, |
| 553 | [10] = { |
| 554 | .name = "mem:0:r", |
| 555 | .check = test__checkevent_breakpoint_r, |
| 556 | }, |
| 557 | [11] = { |
| 558 | .name = "mem:0:w", |
| 559 | .check = test__checkevent_breakpoint_w, |
| 560 | }, |
| 561 | [12] = { |
| 562 | .name = "syscalls:sys_enter_open:k", |
| 563 | .check = test__checkevent_tracepoint_modifier, |
| 564 | }, |
| 565 | [13] = { |
| 566 | .name = "syscalls:*:u", |
| 567 | .check = test__checkevent_tracepoint_multi_modifier, |
| 568 | }, |
| 569 | [14] = { |
| 570 | .name = "r1a:kp", |
| 571 | .check = test__checkevent_raw_modifier, |
| 572 | }, |
| 573 | [15] = { |
| 574 | .name = "1:1:hp", |
| 575 | .check = test__checkevent_numeric_modifier, |
| 576 | }, |
| 577 | [16] = { |
| 578 | .name = "instructions:h", |
| 579 | .check = test__checkevent_symbolic_name_modifier, |
| 580 | }, |
| 581 | [17] = { |
| 582 | .name = "faults:u", |
| 583 | .check = test__checkevent_symbolic_alias_modifier, |
| 584 | }, |
| 585 | [18] = { |
| 586 | .name = "L1-dcache-load-miss:kp", |
| 587 | .check = test__checkevent_genhw_modifier, |
| 588 | }, |
| 589 | [19] = { |
| 590 | .name = "mem:0:u", |
| 591 | .check = test__checkevent_breakpoint_modifier, |
| 592 | }, |
| 593 | [20] = { |
| 594 | .name = "mem:0:x:k", |
| 595 | .check = test__checkevent_breakpoint_x_modifier, |
| 596 | }, |
| 597 | [21] = { |
| 598 | .name = "mem:0:r:hp", |
| 599 | .check = test__checkevent_breakpoint_r_modifier, |
| 600 | }, |
| 601 | [22] = { |
| 602 | .name = "mem:0:w:up", |
| 603 | .check = test__checkevent_breakpoint_w_modifier, |
| 604 | }, |
| 605 | [23] = { |
| 606 | .name = "r1,syscalls:sys_enter_open:k,1:1:hp", |
| 607 | .check = test__checkevent_list, |
| 608 | }, |
| 609 | [24] = { |
| 610 | .name = "instructions:G", |
| 611 | .check = test__checkevent_exclude_host_modifier, |
| 612 | }, |
| 613 | [25] = { |
| 614 | .name = "instructions:H", |
| 615 | .check = test__checkevent_exclude_guest_modifier, |
| 616 | }, |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame^] | 617 | [26] = { |
| 618 | .name = "mem:0:rw", |
| 619 | .check = test__checkevent_breakpoint_rw, |
| 620 | }, |
| 621 | [27] = { |
| 622 | .name = "mem:0:rw:kp", |
| 623 | .check = test__checkevent_breakpoint_rw_modifier, |
| 624 | }, |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 625 | }; |
| 626 | |
| 627 | #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st)) |
| 628 | |
| 629 | static struct test__event_st test__events_pmu[] = { |
| 630 | [0] = { |
| 631 | .name = "cpu/config=10,config1,config2=3,period=1000/u", |
| 632 | .check = test__checkevent_pmu, |
| 633 | }, |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 634 | [1] = { |
| 635 | .name = "cpu/config=1,name=krava/u,cpu/config=2/u", |
| 636 | .check = test__checkevent_pmu_name, |
| 637 | }, |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 638 | }; |
| 639 | |
| 640 | #define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \ |
| 641 | sizeof(struct test__event_st)) |
| 642 | |
Jiri Olsa | 4429392 | 2012-06-15 14:31:42 +0800 | [diff] [blame] | 643 | struct test__term { |
| 644 | const char *str; |
| 645 | __u32 type; |
| 646 | int (*check)(struct list_head *terms); |
| 647 | }; |
| 648 | |
| 649 | static struct test__term test__terms[] = { |
| 650 | [0] = { |
| 651 | .str = "config=10,config1,config2=3,umask=1", |
| 652 | .check = test__checkterms_simple, |
| 653 | }, |
| 654 | }; |
| 655 | |
| 656 | #define TEST__TERMS_CNT (sizeof(test__terms) / \ |
| 657 | sizeof(struct test__term)) |
| 658 | |
| 659 | static int test_event(struct test__event_st *e) |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 660 | { |
| 661 | struct perf_evlist *evlist; |
| 662 | int ret; |
| 663 | |
| 664 | evlist = perf_evlist__new(NULL, NULL); |
| 665 | if (evlist == NULL) |
| 666 | return -ENOMEM; |
| 667 | |
| 668 | ret = parse_events(evlist, e->name, 0); |
| 669 | if (ret) { |
| 670 | pr_debug("failed to parse event '%s', err %d\n", |
| 671 | e->name, ret); |
| 672 | return ret; |
| 673 | } |
| 674 | |
| 675 | ret = e->check(evlist); |
| 676 | perf_evlist__delete(evlist); |
| 677 | |
| 678 | return ret; |
| 679 | } |
| 680 | |
| 681 | static int test_events(struct test__event_st *events, unsigned cnt) |
| 682 | { |
| 683 | int ret = 0; |
| 684 | unsigned i; |
| 685 | |
| 686 | for (i = 0; i < cnt; i++) { |
| 687 | struct test__event_st *e = &events[i]; |
| 688 | |
| 689 | pr_debug("running test %d '%s'\n", i, e->name); |
Jiri Olsa | 4429392 | 2012-06-15 14:31:42 +0800 | [diff] [blame] | 690 | ret = test_event(e); |
| 691 | if (ret) |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | return ret; |
| 696 | } |
| 697 | |
| 698 | static int test_term(struct test__term *t) |
| 699 | { |
| 700 | struct list_head *terms; |
| 701 | int ret; |
| 702 | |
| 703 | terms = malloc(sizeof(*terms)); |
| 704 | if (!terms) |
| 705 | return -ENOMEM; |
| 706 | |
| 707 | INIT_LIST_HEAD(terms); |
| 708 | |
| 709 | ret = parse_events_terms(terms, t->str); |
| 710 | if (ret) { |
| 711 | pr_debug("failed to parse terms '%s', err %d\n", |
| 712 | t->str , ret); |
| 713 | return ret; |
| 714 | } |
| 715 | |
| 716 | ret = t->check(terms); |
| 717 | parse_events__free_terms(terms); |
| 718 | |
| 719 | return ret; |
| 720 | } |
| 721 | |
| 722 | static int test_terms(struct test__term *terms, unsigned cnt) |
| 723 | { |
| 724 | int ret = 0; |
| 725 | unsigned i; |
| 726 | |
| 727 | for (i = 0; i < cnt; i++) { |
| 728 | struct test__term *t = &terms[i]; |
| 729 | |
| 730 | pr_debug("running test %d '%s'\n", i, t->str); |
| 731 | ret = test_term(t); |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 732 | if (ret) |
| 733 | break; |
| 734 | } |
| 735 | |
| 736 | return ret; |
| 737 | } |
| 738 | |
| 739 | static int test_pmu(void) |
| 740 | { |
| 741 | struct stat st; |
| 742 | char path[PATH_MAX]; |
| 743 | int ret; |
| 744 | |
| 745 | snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/", |
| 746 | sysfs_find_mountpoint()); |
| 747 | |
| 748 | ret = stat(path, &st); |
| 749 | if (ret) |
| 750 | pr_debug("ommiting PMU cpu tests\n"); |
| 751 | return !ret; |
| 752 | } |
| 753 | |
| 754 | int parse_events__test(void) |
| 755 | { |
| 756 | int ret; |
| 757 | |
Jiri Olsa | 4429392 | 2012-06-15 14:31:42 +0800 | [diff] [blame] | 758 | do { |
| 759 | ret = test_events(test__events, TEST__EVENTS_CNT); |
| 760 | if (ret) |
| 761 | break; |
| 762 | |
| 763 | if (test_pmu()) { |
| 764 | ret = test_events(test__events_pmu, |
| 765 | TEST__EVENTS_PMU_CNT); |
| 766 | if (ret) |
| 767 | break; |
| 768 | } |
| 769 | |
| 770 | ret = test_terms(test__terms, TEST__TERMS_CNT); |
| 771 | |
| 772 | } while (0); |
Jiri Olsa | f50246e | 2012-05-21 09:12:49 +0200 | [diff] [blame] | 773 | |
| 774 | return ret; |
| 775 | } |