1 // SPDX-License-Identifier: GPL-2.0 2 #include "parse-events.h" 3 #include "evsel.h" 4 #include "evlist.h" 5 #include <api/fs/fs.h> 6 #include "tests.h" 7 #include "debug.h" 8 #include "pmu.h" 9 #include "pmus.h" 10 #include <dirent.h> 11 #include <errno.h> 12 #include "fncache.h" 13 #include <sys/types.h> 14 #include <sys/stat.h> 15 #include <unistd.h> 16 #include <linux/kernel.h> 17 #include <linux/hw_breakpoint.h> 18 #include <api/fs/tracing_path.h> 19 20 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ 21 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) 22 23 static bool test_config(const struct evsel *evsel, __u64 expected_config) 24 { 25 __u32 type = evsel->core.attr.type; 26 __u64 config = evsel->core.attr.config; 27 28 if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) { 29 /* 30 * HARDWARE and HW_CACHE events encode the PMU's extended type 31 * in the top 32-bits. Mask in order to ignore. 32 */ 33 config &= PERF_HW_EVENT_MASK; 34 } 35 return config == expected_config; 36 } 37 38 static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_config) 39 { 40 return (evsel->attr.config & PERF_HW_EVENT_MASK) == expected_config; 41 } 42 43 #ifdef HAVE_LIBTRACEEVENT 44 45 #if defined(__s390x__) 46 /* Return true if kvm module is available and loaded. Test this 47 * and return success when trace point kvm_s390_create_vm 48 * exists. Otherwise this test always fails. 49 */ 50 static bool kvm_s390_create_vm_valid(void) 51 { 52 char *eventfile; 53 bool rc = false; 54 55 eventfile = get_events_file("kvm-s390"); 56 57 if (eventfile) { 58 DIR *mydir = opendir(eventfile); 59 60 if (mydir) { 61 rc = true; 62 closedir(mydir); 63 } 64 put_events_file(eventfile); 65 } 66 67 return rc; 68 } 69 #endif 70 71 static int test__checkevent_tracepoint(struct evlist *evlist) 72 { 73 struct evsel *evsel = evlist__first(evlist); 74 75 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 76 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist)); 77 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type); 78 TEST_ASSERT_VAL("wrong sample_type", 79 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type); 80 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period); 81 return TEST_OK; 82 } 83 84 static int test__checkevent_tracepoint_multi(struct evlist *evlist) 85 { 86 struct evsel *evsel; 87 88 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1); 89 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist)); 90 91 evlist__for_each_entry(evlist, evsel) { 92 TEST_ASSERT_VAL("wrong type", 93 PERF_TYPE_TRACEPOINT == evsel->core.attr.type); 94 TEST_ASSERT_VAL("wrong sample_type", 95 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type); 96 TEST_ASSERT_VAL("wrong sample_period", 97 1 == evsel->core.attr.sample_period); 98 } 99 return TEST_OK; 100 } 101 #endif /* HAVE_LIBTRACEEVENT */ 102 103 static int test__checkevent_raw(struct evlist *evlist) 104 { 105 struct perf_evsel *evsel; 106 bool raw_type_match = false; 107 108 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries); 109 110 perf_evlist__for_each_evsel(&evlist->core, evsel) { 111 struct perf_pmu *pmu __maybe_unused = NULL; 112 bool type_matched = false; 113 114 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); 115 TEST_ASSERT_VAL("event not parsed as raw type", 116 evsel->attr.type == PERF_TYPE_RAW); 117 #if defined(__aarch64__) 118 /* 119 * Arm doesn't have a real raw type PMU in sysfs, so raw events 120 * would never match any PMU. However, RAW events on Arm will 121 * always successfully open on the first available core PMU 122 * so no need to test for a matching type here. 123 */ 124 type_matched = raw_type_match = true; 125 #else 126 while ((pmu = perf_pmus__scan(pmu)) != NULL) { 127 if (pmu->type == evsel->attr.type) { 128 TEST_ASSERT_VAL("PMU type expected once", !type_matched); 129 type_matched = true; 130 if (pmu->type == PERF_TYPE_RAW) 131 raw_type_match = true; 132 } 133 } 134 #endif 135 TEST_ASSERT_VAL("No PMU found for type", type_matched); 136 } 137 TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match); 138 return TEST_OK; 139 } 140 141 static int test__checkevent_numeric(struct evlist *evlist) 142 { 143 struct evsel *evsel = evlist__first(evlist); 144 145 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 146 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type); 147 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); 148 return TEST_OK; 149 } 150 151 static int test__checkevent_symbolic_name(struct evlist *evlist) 152 { 153 struct perf_evsel *evsel; 154 155 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries); 156 157 perf_evlist__for_each_evsel(&evlist->core, evsel) { 158 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 159 TEST_ASSERT_VAL("wrong config", 160 test_perf_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 161 } 162 return TEST_OK; 163 } 164 165 static int test__checkevent_symbolic_name_config(struct evlist *evlist) 166 { 167 struct perf_evsel *evsel; 168 169 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries); 170 171 perf_evlist__for_each_evsel(&evlist->core, evsel) { 172 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 173 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 174 /* 175 * The period value gets configured within evlist__config, 176 * while this test executes only parse events method. 177 */ 178 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); 179 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1); 180 TEST_ASSERT_VAL("wrong config2", 1 == evsel->attr.config2); 181 } 182 return TEST_OK; 183 } 184 185 static int test__checkevent_symbolic_alias(struct evlist *evlist) 186 { 187 struct evsel *evsel = evlist__first(evlist); 188 189 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 190 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type); 191 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS)); 192 return TEST_OK; 193 } 194 195 static int test__checkevent_genhw(struct evlist *evlist) 196 { 197 struct perf_evsel *evsel; 198 199 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries); 200 201 perf_evlist__for_each_entry(&evlist->core, evsel) { 202 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type); 203 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 1 << 16)); 204 } 205 return TEST_OK; 206 } 207 208 static int test__checkevent_breakpoint(struct evlist *evlist) 209 { 210 struct evsel *evsel = evlist__first(evlist); 211 212 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 213 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 214 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 215 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == 216 evsel->core.attr.bp_type); 217 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 == 218 evsel->core.attr.bp_len); 219 return TEST_OK; 220 } 221 222 static int test__checkevent_breakpoint_x(struct evlist *evlist) 223 { 224 struct evsel *evsel = evlist__first(evlist); 225 226 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 227 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 228 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 229 TEST_ASSERT_VAL("wrong bp_type", 230 HW_BREAKPOINT_X == evsel->core.attr.bp_type); 231 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len); 232 return TEST_OK; 233 } 234 235 static int test__checkevent_breakpoint_r(struct evlist *evlist) 236 { 237 struct evsel *evsel = evlist__first(evlist); 238 239 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 240 TEST_ASSERT_VAL("wrong type", 241 PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 242 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 243 TEST_ASSERT_VAL("wrong bp_type", 244 HW_BREAKPOINT_R == evsel->core.attr.bp_type); 245 TEST_ASSERT_VAL("wrong bp_len", 246 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len); 247 return TEST_OK; 248 } 249 250 static int test__checkevent_breakpoint_w(struct evlist *evlist) 251 { 252 struct evsel *evsel = evlist__first(evlist); 253 254 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 255 TEST_ASSERT_VAL("wrong type", 256 PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 257 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 258 TEST_ASSERT_VAL("wrong bp_type", 259 HW_BREAKPOINT_W == evsel->core.attr.bp_type); 260 TEST_ASSERT_VAL("wrong bp_len", 261 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len); 262 return TEST_OK; 263 } 264 265 static int test__checkevent_breakpoint_rw(struct evlist *evlist) 266 { 267 struct evsel *evsel = evlist__first(evlist); 268 269 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 270 TEST_ASSERT_VAL("wrong type", 271 PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 272 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 273 TEST_ASSERT_VAL("wrong bp_type", 274 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type); 275 TEST_ASSERT_VAL("wrong bp_len", 276 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len); 277 return TEST_OK; 278 } 279 280 #ifdef HAVE_LIBTRACEEVENT 281 static int test__checkevent_tracepoint_modifier(struct evlist *evlist) 282 { 283 struct evsel *evsel = evlist__first(evlist); 284 285 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 286 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 287 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 288 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 289 290 return test__checkevent_tracepoint(evlist); 291 } 292 293 static int 294 test__checkevent_tracepoint_multi_modifier(struct evlist *evlist) 295 { 296 struct perf_evsel *evsel; 297 298 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1); 299 300 perf_evlist__for_each_entry(&evlist->core, evsel) { 301 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 302 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 303 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 304 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 305 } 306 307 return test__checkevent_tracepoint_multi(evlist); 308 } 309 #endif /* HAVE_LIBTRACEEVENT */ 310 311 static int test__checkevent_raw_modifier(struct evlist *evlist) 312 { 313 struct perf_evsel *evsel; 314 315 perf_evlist__for_each_entry(&evlist->core, evsel) { 316 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 317 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 318 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 319 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 320 } 321 return test__checkevent_raw(evlist); 322 } 323 324 static int test__checkevent_numeric_modifier(struct evlist *evlist) 325 { 326 struct perf_evsel *evsel; 327 328 perf_evlist__for_each_entry(&evlist->core, evsel) { 329 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 330 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 331 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 332 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 333 } 334 return test__checkevent_numeric(evlist); 335 } 336 337 static int test__checkevent_symbolic_name_modifier(struct evlist *evlist) 338 { 339 struct perf_evsel *evsel; 340 341 TEST_ASSERT_VAL("wrong number of entries", 342 evlist->core.nr_entries == perf_pmus__num_core_pmus()); 343 344 perf_evlist__for_each_entry(&evlist->core, evsel) { 345 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 346 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 347 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 348 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 349 } 350 return test__checkevent_symbolic_name(evlist); 351 } 352 353 static int test__checkevent_exclude_host_modifier(struct evlist *evlist) 354 { 355 struct perf_evsel *evsel; 356 357 perf_evlist__for_each_entry(&evlist->core, evsel) { 358 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 359 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 360 } 361 return test__checkevent_symbolic_name(evlist); 362 } 363 364 static int test__checkevent_exclude_guest_modifier(struct evlist *evlist) 365 { 366 struct perf_evsel *evsel; 367 368 perf_evlist__for_each_entry(&evlist->core, evsel) { 369 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 370 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 371 } 372 return test__checkevent_symbolic_name(evlist); 373 } 374 375 static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist) 376 { 377 struct evsel *evsel = evlist__first(evlist); 378 379 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 380 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 381 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 382 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 383 384 return test__checkevent_symbolic_alias(evlist); 385 } 386 387 static int test__checkevent_genhw_modifier(struct evlist *evlist) 388 { 389 struct perf_evsel *evsel; 390 391 perf_evlist__for_each_entry(&evlist->core, evsel) { 392 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 393 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 394 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 395 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 396 } 397 return test__checkevent_genhw(evlist); 398 } 399 400 static int test__checkevent_exclude_idle_modifier(struct evlist *evlist) 401 { 402 struct evsel *evsel = evlist__first(evlist); 403 404 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle); 405 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 406 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 407 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 408 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 409 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 410 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 411 412 return test__checkevent_symbolic_name(evlist); 413 } 414 415 static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist) 416 { 417 struct evsel *evsel = evlist__first(evlist); 418 419 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle); 420 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 421 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 422 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 423 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 424 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 425 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 426 427 return test__checkevent_symbolic_name(evlist); 428 } 429 430 static int test__checkevent_breakpoint_modifier(struct evlist *evlist) 431 { 432 struct evsel *evsel = evlist__first(evlist); 433 434 435 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 436 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 437 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 438 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 439 TEST_ASSERT_VAL("wrong name", 440 !strcmp(evsel__name(evsel), "mem:0:u")); 441 442 return test__checkevent_breakpoint(evlist); 443 } 444 445 static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist) 446 { 447 struct evsel *evsel = evlist__first(evlist); 448 449 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 450 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 451 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 452 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 453 TEST_ASSERT_VAL("wrong name", 454 !strcmp(evsel__name(evsel), "mem:0:x:k")); 455 456 return test__checkevent_breakpoint_x(evlist); 457 } 458 459 static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist) 460 { 461 struct evsel *evsel = evlist__first(evlist); 462 463 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 464 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 465 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 466 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 467 TEST_ASSERT_VAL("wrong name", 468 !strcmp(evsel__name(evsel), "mem:0:r:hp")); 469 470 return test__checkevent_breakpoint_r(evlist); 471 } 472 473 static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist) 474 { 475 struct evsel *evsel = evlist__first(evlist); 476 477 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 478 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 479 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 480 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 481 TEST_ASSERT_VAL("wrong name", 482 !strcmp(evsel__name(evsel), "mem:0:w:up")); 483 484 return test__checkevent_breakpoint_w(evlist); 485 } 486 487 static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist) 488 { 489 struct evsel *evsel = evlist__first(evlist); 490 491 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 492 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 493 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 494 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 495 TEST_ASSERT_VAL("wrong name", 496 !strcmp(evsel__name(evsel), "mem:0:rw:kp")); 497 498 return test__checkevent_breakpoint_rw(evlist); 499 } 500 501 static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist) 502 { 503 struct evsel *evsel = evlist__first(evlist); 504 505 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 506 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 507 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 508 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 509 TEST_ASSERT_VAL("wrong name", 510 !strcmp(evsel__name(evsel), "breakpoint")); 511 512 return test__checkevent_breakpoint(evlist); 513 } 514 515 static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist) 516 { 517 struct evsel *evsel = evlist__first(evlist); 518 519 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 520 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 521 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 522 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 523 TEST_ASSERT_VAL("wrong name", 524 !strcmp(evsel__name(evsel), "breakpoint")); 525 526 return test__checkevent_breakpoint_x(evlist); 527 } 528 529 static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist) 530 { 531 struct evsel *evsel = evlist__first(evlist); 532 533 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 534 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 535 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 536 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 537 TEST_ASSERT_VAL("wrong name", 538 !strcmp(evsel__name(evsel), "breakpoint")); 539 540 return test__checkevent_breakpoint_r(evlist); 541 } 542 543 static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist) 544 { 545 struct evsel *evsel = evlist__first(evlist); 546 547 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 548 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 549 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 550 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 551 TEST_ASSERT_VAL("wrong name", 552 !strcmp(evsel__name(evsel), "breakpoint")); 553 554 return test__checkevent_breakpoint_w(evlist); 555 } 556 557 static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist) 558 { 559 struct evsel *evsel = evlist__first(evlist); 560 561 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 562 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 563 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 564 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 565 TEST_ASSERT_VAL("wrong name", 566 !strcmp(evsel__name(evsel), "breakpoint")); 567 568 return test__checkevent_breakpoint_rw(evlist); 569 } 570 571 static int test__checkevent_breakpoint_2_events(struct evlist *evlist) 572 { 573 struct evsel *evsel = evlist__first(evlist); 574 575 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 576 577 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 578 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint1")); 579 580 evsel = evsel__next(evsel); 581 582 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 583 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint2")); 584 585 return TEST_OK; 586 } 587 588 static int test__checkevent_pmu(struct evlist *evlist) 589 { 590 591 struct evsel *evsel = evlist__first(evlist); 592 593 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 594 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 595 TEST_ASSERT_VAL("wrong config", test_config(evsel, 10)); 596 TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1); 597 TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2); 598 TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3); 599 /* 600 * The period value gets configured within evlist__config, 601 * while this test executes only parse events method. 602 */ 603 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period); 604 605 return TEST_OK; 606 } 607 608 #ifdef HAVE_LIBTRACEEVENT 609 static int test__checkevent_list(struct evlist *evlist) 610 { 611 struct evsel *evsel = evlist__first(evlist); 612 613 TEST_ASSERT_VAL("wrong number of entries", 3 <= evlist->core.nr_entries); 614 615 /* r1 */ 616 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT != evsel->core.attr.type); 617 while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) { 618 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); 619 TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1); 620 TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2); 621 TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3); 622 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 623 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 624 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 625 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 626 evsel = evsel__next(evsel); 627 } 628 629 /* syscalls:sys_enter_openat:k */ 630 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type); 631 TEST_ASSERT_VAL("wrong sample_type", 632 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type); 633 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period); 634 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 635 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 636 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 637 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 638 639 /* 1:1:hp */ 640 evsel = evsel__next(evsel); 641 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type); 642 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); 643 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 644 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 645 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 646 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 647 648 return TEST_OK; 649 } 650 #endif 651 652 static int test__checkevent_pmu_name(struct evlist *evlist) 653 { 654 struct evsel *evsel = evlist__first(evlist); 655 656 /* cpu/config=1,name=krava/u */ 657 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 659 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); 660 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava")); 661 662 /* cpu/config=2/u" */ 663 evsel = evsel__next(evsel); 664 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 665 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 666 TEST_ASSERT_VAL("wrong config", test_config(evsel, 2)); 667 TEST_ASSERT_VAL("wrong name", 668 !strcmp(evsel__name(evsel), "cpu/config=2/u")); 669 670 return TEST_OK; 671 } 672 673 static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist) 674 { 675 struct evsel *evsel = evlist__first(evlist); 676 677 /* cpu/config=1,call-graph=fp,time,period=100000/ */ 678 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 679 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 680 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); 681 /* 682 * The period, time and callgraph value gets configured within evlist__config, 683 * while this test executes only parse events method. 684 */ 685 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period); 686 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel)); 687 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type)); 688 689 /* cpu/config=2,call-graph=no,time=0,period=2000/ */ 690 evsel = evsel__next(evsel); 691 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 692 TEST_ASSERT_VAL("wrong config", test_config(evsel, 2)); 693 /* 694 * The period, time and callgraph value gets configured within evlist__config, 695 * while this test executes only parse events method. 696 */ 697 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period); 698 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel)); 699 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type)); 700 701 return TEST_OK; 702 } 703 704 static int test__checkevent_pmu_events(struct evlist *evlist) 705 { 706 struct evsel *evsel = evlist__first(evlist); 707 708 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 709 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type || 710 strcmp(evsel->pmu_name, "cpu")); 711 TEST_ASSERT_VAL("wrong exclude_user", 712 !evsel->core.attr.exclude_user); 713 TEST_ASSERT_VAL("wrong exclude_kernel", 714 evsel->core.attr.exclude_kernel); 715 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 716 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 717 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); 718 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive); 719 720 return TEST_OK; 721 } 722 723 724 static int test__checkevent_pmu_events_mix(struct evlist *evlist) 725 { 726 struct evsel *evsel = NULL; 727 728 /* 729 * The wild card event will be opened at least once, but it may be 730 * opened on each core PMU. 731 */ 732 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries >= 2); 733 for (int i = 0; i < evlist->core.nr_entries - 1; i++) { 734 evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 735 /* pmu-event:u */ 736 TEST_ASSERT_VAL("wrong exclude_user", 737 !evsel->core.attr.exclude_user); 738 TEST_ASSERT_VAL("wrong exclude_kernel", 739 evsel->core.attr.exclude_kernel); 740 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 741 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 742 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); 743 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive); 744 } 745 /* cpu/pmu-event/u*/ 746 evsel = evsel__next(evsel); 747 TEST_ASSERT_VAL("wrong type", evsel__find_pmu(evsel)->is_core); 748 TEST_ASSERT_VAL("wrong exclude_user", 749 !evsel->core.attr.exclude_user); 750 TEST_ASSERT_VAL("wrong exclude_kernel", 751 evsel->core.attr.exclude_kernel); 752 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 753 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 754 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); 755 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned); 756 757 return TEST_OK; 758 } 759 760 static int test__checkterms_simple(struct list_head *terms) 761 { 762 struct parse_events_term *term; 763 764 /* config=10 */ 765 term = list_entry(terms->next, struct parse_events_term, list); 766 TEST_ASSERT_VAL("wrong type term", 767 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG); 768 TEST_ASSERT_VAL("wrong type val", 769 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 770 TEST_ASSERT_VAL("wrong val", term->val.num == 10); 771 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config")); 772 773 /* config1 */ 774 term = list_entry(term->list.next, struct parse_events_term, list); 775 TEST_ASSERT_VAL("wrong type term", 776 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1); 777 TEST_ASSERT_VAL("wrong type val", 778 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 779 TEST_ASSERT_VAL("wrong val", term->val.num == 1); 780 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1")); 781 782 /* config2=3 */ 783 term = list_entry(term->list.next, struct parse_events_term, list); 784 TEST_ASSERT_VAL("wrong type term", 785 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2); 786 TEST_ASSERT_VAL("wrong type val", 787 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 788 TEST_ASSERT_VAL("wrong val", term->val.num == 3); 789 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2")); 790 791 /* config3=4 */ 792 term = list_entry(term->list.next, struct parse_events_term, list); 793 TEST_ASSERT_VAL("wrong type term", 794 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3); 795 TEST_ASSERT_VAL("wrong type val", 796 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 797 TEST_ASSERT_VAL("wrong val", term->val.num == 4); 798 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config3")); 799 800 /* umask=1*/ 801 term = list_entry(term->list.next, struct parse_events_term, list); 802 TEST_ASSERT_VAL("wrong type term", 803 term->type_term == PARSE_EVENTS__TERM_TYPE_USER); 804 TEST_ASSERT_VAL("wrong type val", 805 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 806 TEST_ASSERT_VAL("wrong val", term->val.num == 1); 807 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask")); 808 809 /* 810 * read 811 * 812 * The perf_pmu__test_parse_init injects 'read' term into 813 * perf_pmu_events_list, so 'read' is evaluated as read term 814 * and not as raw event with 'ead' hex value. 815 */ 816 term = list_entry(term->list.next, struct parse_events_term, list); 817 TEST_ASSERT_VAL("wrong type term", 818 term->type_term == PARSE_EVENTS__TERM_TYPE_RAW); 819 TEST_ASSERT_VAL("wrong type val", 820 term->type_val == PARSE_EVENTS__TERM_TYPE_STR); 821 TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "read")); 822 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw")); 823 824 /* 825 * r0xead 826 * 827 * To be still able to pass 'ead' value with 'r' syntax, 828 * we added support to parse 'r0xHEX' event. 829 */ 830 term = list_entry(term->list.next, struct parse_events_term, list); 831 TEST_ASSERT_VAL("wrong type term", 832 term->type_term == PARSE_EVENTS__TERM_TYPE_RAW); 833 TEST_ASSERT_VAL("wrong type val", 834 term->type_val == PARSE_EVENTS__TERM_TYPE_STR); 835 TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "r0xead")); 836 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw")); 837 return TEST_OK; 838 } 839 840 static int test__group1(struct evlist *evlist) 841 { 842 struct evsel *evsel, *leader; 843 844 TEST_ASSERT_VAL("wrong number of entries", 845 evlist->core.nr_entries == (perf_pmus__num_core_pmus() * 2)); 846 TEST_ASSERT_VAL("wrong number of groups", 847 evlist__nr_groups(evlist) == perf_pmus__num_core_pmus()); 848 849 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 850 /* instructions:k */ 851 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 852 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 853 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 854 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 855 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 856 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 857 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 858 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 859 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 860 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 861 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 862 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 863 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 864 865 /* cycles:upp */ 866 evsel = evsel__next(evsel); 867 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 868 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 869 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 870 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 871 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 872 /* use of precise requires exclude_guest */ 873 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 874 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 875 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2); 876 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 877 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 878 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 879 } 880 return TEST_OK; 881 } 882 883 static int test__group2(struct evlist *evlist) 884 { 885 struct evsel *evsel, *leader = NULL; 886 887 TEST_ASSERT_VAL("wrong number of entries", 888 evlist->core.nr_entries == (2 * perf_pmus__num_core_pmus() + 1)); 889 /* 890 * TODO: Currently the software event won't be grouped with the hardware 891 * event except for 1 PMU. 892 */ 893 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist)); 894 895 evlist__for_each_entry(evlist, evsel) { 896 if (evsel->core.attr.type == PERF_TYPE_SOFTWARE) { 897 /* faults + :ku modifier */ 898 leader = evsel; 899 TEST_ASSERT_VAL("wrong config", 900 test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS)); 901 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 902 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 903 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 904 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 905 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 906 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 907 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 908 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 909 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 910 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 911 continue; 912 } 913 if (evsel->core.attr.type == PERF_TYPE_HARDWARE && 914 test_config(evsel, PERF_COUNT_HW_CACHE_REFERENCES)) { 915 /* cache-references + :u modifier */ 916 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 917 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 918 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 919 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 920 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 921 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 922 if (evsel__has_leader(evsel, leader)) 923 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 924 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 925 continue; 926 } 927 /* cycles:k */ 928 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 929 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 930 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 931 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 932 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 933 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 934 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 935 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 936 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 937 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 938 } 939 return TEST_OK; 940 } 941 942 #ifdef HAVE_LIBTRACEEVENT 943 static int test__group3(struct evlist *evlist __maybe_unused) 944 { 945 struct evsel *evsel, *group1_leader = NULL, *group2_leader = NULL; 946 947 TEST_ASSERT_VAL("wrong number of entries", 948 evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus() + 2)); 949 /* 950 * Currently the software event won't be grouped with the hardware event 951 * except for 1 PMU. This means there are always just 2 groups 952 * regardless of the number of core PMUs. 953 */ 954 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist)); 955 956 evlist__for_each_entry(evlist, evsel) { 957 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) { 958 /* group1 syscalls:sys_enter_openat:H */ 959 group1_leader = evsel; 960 TEST_ASSERT_VAL("wrong sample_type", 961 evsel->core.attr.sample_type == PERF_TP_SAMPLE_TYPE); 962 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period); 963 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 964 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 965 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 966 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 967 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 968 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 969 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 970 TEST_ASSERT_VAL("wrong group name", !strcmp(evsel->group_name, "group1")); 971 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 972 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 973 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 974 continue; 975 } 976 if (evsel->core.attr.type == PERF_TYPE_HARDWARE && 977 test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)) { 978 if (evsel->core.attr.exclude_user) { 979 /* group1 cycles:kppp */ 980 TEST_ASSERT_VAL("wrong exclude_user", 981 evsel->core.attr.exclude_user); 982 TEST_ASSERT_VAL("wrong exclude_kernel", 983 !evsel->core.attr.exclude_kernel); 984 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 985 /* use of precise requires exclude_guest */ 986 TEST_ASSERT_VAL("wrong exclude guest", 987 evsel->core.attr.exclude_guest); 988 TEST_ASSERT_VAL("wrong exclude host", 989 !evsel->core.attr.exclude_host); 990 TEST_ASSERT_VAL("wrong precise_ip", 991 evsel->core.attr.precise_ip == 3); 992 if (evsel__has_leader(evsel, group1_leader)) { 993 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 994 TEST_ASSERT_VAL("wrong group_idx", 995 evsel__group_idx(evsel) == 1); 996 } 997 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 998 } else { 999 /* group2 cycles + G modifier */ 1000 group2_leader = evsel; 1001 TEST_ASSERT_VAL("wrong exclude_kernel", 1002 !evsel->core.attr.exclude_kernel); 1003 TEST_ASSERT_VAL("wrong exclude_hv", 1004 !evsel->core.attr.exclude_hv); 1005 TEST_ASSERT_VAL("wrong exclude guest", 1006 !evsel->core.attr.exclude_guest); 1007 TEST_ASSERT_VAL("wrong exclude host", 1008 evsel->core.attr.exclude_host); 1009 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1010 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1011 if (evsel->core.nr_members == 2) { 1012 TEST_ASSERT_VAL("wrong group_idx", 1013 evsel__group_idx(evsel) == 0); 1014 } 1015 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1016 } 1017 continue; 1018 } 1019 if (evsel->core.attr.type == 1) { 1020 /* group2 1:3 + G modifier */ 1021 TEST_ASSERT_VAL("wrong config", test_config(evsel, 3)); 1022 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1023 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1024 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1025 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1026 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1027 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1028 if (evsel__has_leader(evsel, group2_leader)) 1029 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1030 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1031 continue; 1032 } 1033 /* instructions:u */ 1034 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1035 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 1036 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1037 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1038 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1039 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1040 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1041 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1042 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1043 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1044 } 1045 return TEST_OK; 1046 } 1047 #endif 1048 1049 static int test__group4(struct evlist *evlist __maybe_unused) 1050 { 1051 struct evsel *evsel, *leader; 1052 1053 TEST_ASSERT_VAL("wrong number of entries", 1054 evlist->core.nr_entries == (perf_pmus__num_core_pmus() * 2)); 1055 TEST_ASSERT_VAL("wrong number of groups", 1056 perf_pmus__num_core_pmus() == evlist__nr_groups(evlist)); 1057 1058 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1059 /* cycles:u + p */ 1060 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1061 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1062 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1063 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1064 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1065 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1066 /* use of precise requires exclude_guest */ 1067 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1068 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1069 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1); 1070 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1071 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1072 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1073 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1074 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1075 1076 /* instructions:kp + p */ 1077 evsel = evsel__next(evsel); 1078 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1079 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 1080 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 1081 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1082 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1083 /* use of precise requires exclude_guest */ 1084 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1085 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1086 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2); 1087 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1088 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1089 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1090 } 1091 return TEST_OK; 1092 } 1093 1094 static int test__group5(struct evlist *evlist __maybe_unused) 1095 { 1096 struct evsel *evsel = NULL, *leader; 1097 1098 TEST_ASSERT_VAL("wrong number of entries", 1099 evlist->core.nr_entries == (5 * perf_pmus__num_core_pmus())); 1100 TEST_ASSERT_VAL("wrong number of groups", 1101 evlist__nr_groups(evlist) == (2 * perf_pmus__num_core_pmus())); 1102 1103 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1104 /* cycles + G */ 1105 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1106 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1107 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1108 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1109 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1110 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1111 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1112 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1113 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1114 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1115 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1116 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1117 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1118 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1119 1120 /* instructions + G */ 1121 evsel = evsel__next(evsel); 1122 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1123 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 1124 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1125 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1126 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1127 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1128 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1129 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1130 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1131 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1132 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1133 } 1134 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1135 /* cycles:G */ 1136 evsel = leader = evsel__next(evsel); 1137 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1138 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1139 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1140 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1141 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1142 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1143 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1144 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1145 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1146 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1147 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1148 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1149 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 1150 1151 /* instructions:G */ 1152 evsel = evsel__next(evsel); 1153 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1154 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 1155 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1156 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1157 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1158 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1159 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1160 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1161 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1162 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1163 } 1164 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1165 /* cycles */ 1166 evsel = evsel__next(evsel); 1167 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1168 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1169 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1170 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1171 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1172 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1173 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1174 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1175 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1176 } 1177 return TEST_OK; 1178 } 1179 1180 static int test__group_gh1(struct evlist *evlist) 1181 { 1182 struct evsel *evsel = NULL, *leader; 1183 1184 TEST_ASSERT_VAL("wrong number of entries", 1185 evlist->core.nr_entries == (2 * perf_pmus__num_core_pmus())); 1186 TEST_ASSERT_VAL("wrong number of groups", 1187 evlist__nr_groups(evlist) == perf_pmus__num_core_pmus()); 1188 1189 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1190 /* cycles + :H group modifier */ 1191 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1192 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1193 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1194 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1195 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1196 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1197 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1198 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1199 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1200 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1201 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1202 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1203 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1204 1205 /* cache-misses:G + :H group modifier */ 1206 evsel = evsel__next(evsel); 1207 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1208 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1209 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1210 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1211 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1212 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1213 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1214 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1215 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1216 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1217 } 1218 return TEST_OK; 1219 } 1220 1221 static int test__group_gh2(struct evlist *evlist) 1222 { 1223 struct evsel *evsel = NULL, *leader; 1224 1225 TEST_ASSERT_VAL("wrong number of entries", 1226 evlist->core.nr_entries == (2 * perf_pmus__num_core_pmus())); 1227 TEST_ASSERT_VAL("wrong number of groups", 1228 evlist__nr_groups(evlist) == perf_pmus__num_core_pmus()); 1229 1230 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1231 /* cycles + :G group modifier */ 1232 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1233 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1234 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1235 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1236 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1237 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1238 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1239 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1240 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1241 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1242 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1243 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1244 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1245 1246 /* cache-misses:H + :G group modifier */ 1247 evsel = evsel__next(evsel); 1248 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1249 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1250 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1251 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1252 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1253 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1254 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1255 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1256 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1257 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1258 } 1259 return TEST_OK; 1260 } 1261 1262 static int test__group_gh3(struct evlist *evlist) 1263 { 1264 struct evsel *evsel = NULL, *leader; 1265 1266 TEST_ASSERT_VAL("wrong number of entries", 1267 evlist->core.nr_entries == (2 * perf_pmus__num_core_pmus())); 1268 TEST_ASSERT_VAL("wrong number of groups", 1269 evlist__nr_groups(evlist) == perf_pmus__num_core_pmus()); 1270 1271 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1272 /* cycles:G + :u group modifier */ 1273 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1274 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1275 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1276 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1277 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1278 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1279 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1280 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1281 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1282 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1283 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1284 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1285 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1286 1287 /* cache-misses:H + :u group modifier */ 1288 evsel = evsel__next(evsel); 1289 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1290 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1291 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1292 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1293 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1294 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1295 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1296 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1297 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1298 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1299 } 1300 return TEST_OK; 1301 } 1302 1303 static int test__group_gh4(struct evlist *evlist) 1304 { 1305 struct evsel *evsel = NULL, *leader; 1306 1307 TEST_ASSERT_VAL("wrong number of entries", 1308 evlist->core.nr_entries == (2 * perf_pmus__num_core_pmus())); 1309 TEST_ASSERT_VAL("wrong number of groups", 1310 evlist__nr_groups(evlist) == perf_pmus__num_core_pmus()); 1311 1312 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1313 /* cycles:G + :uG group modifier */ 1314 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1315 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1316 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1317 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1318 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1319 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1320 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1321 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); 1322 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1323 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1324 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); 1325 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); 1326 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); 1327 1328 /* cache-misses:H + :uG group modifier */ 1329 evsel = evsel__next(evsel); 1330 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1331 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1332 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1333 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1334 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1335 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1336 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1337 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1338 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1339 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); 1340 } 1341 return TEST_OK; 1342 } 1343 1344 static int test__leader_sample1(struct evlist *evlist) 1345 { 1346 struct evsel *evsel = NULL, *leader; 1347 1348 TEST_ASSERT_VAL("wrong number of entries", 1349 evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus())); 1350 1351 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1352 /* cycles - sampling group leader */ 1353 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1354 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1355 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1356 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1357 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1358 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1359 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1360 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1361 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1362 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1363 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1364 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1365 1366 /* cache-misses - not sampling */ 1367 evsel = evsel__next(evsel); 1368 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1369 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1370 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1371 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1372 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1373 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1374 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1375 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1376 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1377 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1378 1379 /* branch-misses - not sampling */ 1380 evsel = evsel__next(evsel); 1381 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1382 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES)); 1383 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1384 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1385 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1386 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1387 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1388 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1389 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1390 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1391 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1392 } 1393 return TEST_OK; 1394 } 1395 1396 static int test__leader_sample2(struct evlist *evlist __maybe_unused) 1397 { 1398 struct evsel *evsel = NULL, *leader; 1399 1400 TEST_ASSERT_VAL("wrong number of entries", 1401 evlist->core.nr_entries == (2 * perf_pmus__num_core_pmus())); 1402 1403 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1404 /* instructions - sampling group leader */ 1405 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1406 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1407 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); 1408 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1409 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1410 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1411 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1412 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1413 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1414 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1415 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1416 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1417 1418 /* branch-misses - not sampling */ 1419 evsel = evsel__next(evsel); 1420 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1421 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES)); 1422 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1423 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1424 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1425 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1426 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1427 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1428 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1429 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1430 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1431 } 1432 return TEST_OK; 1433 } 1434 1435 static int test__checkevent_pinned_modifier(struct evlist *evlist) 1436 { 1437 struct evsel *evsel = NULL; 1438 1439 TEST_ASSERT_VAL("wrong number of entries", 1440 evlist->core.nr_entries == perf_pmus__num_core_pmus()); 1441 1442 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1443 evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1444 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1445 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1446 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1447 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 1448 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned); 1449 } 1450 return test__checkevent_symbolic_name(evlist); 1451 } 1452 1453 static int test__pinned_group(struct evlist *evlist) 1454 { 1455 struct evsel *evsel = NULL, *leader; 1456 1457 TEST_ASSERT_VAL("wrong number of entries", 1458 evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus())); 1459 1460 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1461 /* cycles - group leader */ 1462 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1463 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1464 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1465 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1466 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1467 /* TODO: The group modifier is not copied to the split group leader. */ 1468 if (perf_pmus__num_core_pmus() == 1) 1469 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned); 1470 1471 /* cache-misses - can not be pinned, but will go on with the leader */ 1472 evsel = evsel__next(evsel); 1473 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1474 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1475 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); 1476 1477 /* branch-misses - ditto */ 1478 evsel = evsel__next(evsel); 1479 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES)); 1480 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned); 1481 } 1482 return TEST_OK; 1483 } 1484 1485 static int test__checkevent_exclusive_modifier(struct evlist *evlist) 1486 { 1487 struct evsel *evsel = evlist__first(evlist); 1488 1489 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1490 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1491 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1492 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); 1493 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive); 1494 1495 return test__checkevent_symbolic_name(evlist); 1496 } 1497 1498 static int test__exclusive_group(struct evlist *evlist) 1499 { 1500 struct evsel *evsel = NULL, *leader; 1501 1502 TEST_ASSERT_VAL("wrong number of entries", 1503 evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus())); 1504 1505 for (int i = 0; i < perf_pmus__num_core_pmus(); i++) { 1506 /* cycles - group leader */ 1507 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel)); 1508 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1509 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1510 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1511 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1512 /* TODO: The group modifier is not copied to the split group leader. */ 1513 if (perf_pmus__num_core_pmus() == 1) 1514 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive); 1515 1516 /* cache-misses - can not be pinned, but will go on with the leader */ 1517 evsel = evsel__next(evsel); 1518 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type); 1519 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES)); 1520 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive); 1521 1522 /* branch-misses - ditto */ 1523 evsel = evsel__next(evsel); 1524 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES)); 1525 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive); 1526 } 1527 return TEST_OK; 1528 } 1529 static int test__checkevent_breakpoint_len(struct evlist *evlist) 1530 { 1531 struct evsel *evsel = evlist__first(evlist); 1532 1533 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1534 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 1535 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 1536 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == 1537 evsel->core.attr.bp_type); 1538 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 == 1539 evsel->core.attr.bp_len); 1540 1541 return TEST_OK; 1542 } 1543 1544 static int test__checkevent_breakpoint_len_w(struct evlist *evlist) 1545 { 1546 struct evsel *evsel = evlist__first(evlist); 1547 1548 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1549 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type); 1550 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0)); 1551 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W == 1552 evsel->core.attr.bp_type); 1553 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 == 1554 evsel->core.attr.bp_len); 1555 1556 return TEST_OK; 1557 } 1558 1559 static int 1560 test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist) 1561 { 1562 struct evsel *evsel = evlist__first(evlist); 1563 1564 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1565 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1566 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1567 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1568 1569 return test__checkevent_breakpoint_rw(evlist); 1570 } 1571 1572 static int test__checkevent_precise_max_modifier(struct evlist *evlist) 1573 { 1574 struct evsel *evsel = evlist__first(evlist); 1575 1576 TEST_ASSERT_VAL("wrong number of entries", 1577 evlist->core.nr_entries == (1 + perf_pmus__num_core_pmus())); 1578 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type); 1579 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_TASK_CLOCK)); 1580 return TEST_OK; 1581 } 1582 1583 static int test__checkevent_config_symbol(struct evlist *evlist) 1584 { 1585 struct evsel *evsel = evlist__first(evlist); 1586 1587 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "insn")); 1588 return TEST_OK; 1589 } 1590 1591 static int test__checkevent_config_raw(struct evlist *evlist) 1592 { 1593 struct evsel *evsel = evlist__first(evlist); 1594 1595 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "rawpmu")); 1596 return TEST_OK; 1597 } 1598 1599 static int test__checkevent_config_num(struct evlist *evlist) 1600 { 1601 struct evsel *evsel = evlist__first(evlist); 1602 1603 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "numpmu")); 1604 return TEST_OK; 1605 } 1606 1607 static int test__checkevent_config_cache(struct evlist *evlist) 1608 { 1609 struct evsel *evsel = evlist__first(evlist); 1610 1611 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "cachepmu")); 1612 return test__checkevent_genhw(evlist); 1613 } 1614 1615 static bool test__pmu_cpu_valid(void) 1616 { 1617 return !!perf_pmus__find("cpu"); 1618 } 1619 1620 static bool test__intel_pt_valid(void) 1621 { 1622 return !!perf_pmus__find("intel_pt"); 1623 } 1624 1625 static int test__intel_pt(struct evlist *evlist) 1626 { 1627 struct evsel *evsel = evlist__first(evlist); 1628 1629 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "intel_pt//u")); 1630 return TEST_OK; 1631 } 1632 1633 static int test__checkevent_complex_name(struct evlist *evlist) 1634 { 1635 struct evsel *evsel = evlist__first(evlist); 1636 1637 TEST_ASSERT_VAL("wrong complex name parsing", 1638 evsel__name_is(evsel, 1639 "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks")); 1640 return TEST_OK; 1641 } 1642 1643 static int test__checkevent_raw_pmu(struct evlist *evlist) 1644 { 1645 struct evsel *evsel = evlist__first(evlist); 1646 1647 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1648 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type); 1649 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a)); 1650 return TEST_OK; 1651 } 1652 1653 static int test__sym_event_slash(struct evlist *evlist) 1654 { 1655 struct evsel *evsel = evlist__first(evlist); 1656 1657 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE); 1658 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1659 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1660 return TEST_OK; 1661 } 1662 1663 static int test__sym_event_dc(struct evlist *evlist) 1664 { 1665 struct evsel *evsel = evlist__first(evlist); 1666 1667 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE); 1668 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1669 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 1670 return TEST_OK; 1671 } 1672 1673 static int test__term_equal_term(struct evlist *evlist) 1674 { 1675 struct evsel *evsel = evlist__first(evlist); 1676 1677 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE); 1678 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1679 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "name") == 0); 1680 return TEST_OK; 1681 } 1682 1683 static int test__term_equal_legacy(struct evlist *evlist) 1684 { 1685 struct evsel *evsel = evlist__first(evlist); 1686 1687 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE); 1688 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)); 1689 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "l1d") == 0); 1690 return TEST_OK; 1691 } 1692 1693 #ifdef HAVE_LIBTRACEEVENT 1694 static int count_tracepoints(void) 1695 { 1696 struct dirent *events_ent; 1697 DIR *events_dir; 1698 int cnt = 0; 1699 1700 events_dir = tracing_events__opendir(); 1701 1702 TEST_ASSERT_VAL("Can't open events dir", events_dir); 1703 1704 while ((events_ent = readdir(events_dir))) { 1705 char *sys_path; 1706 struct dirent *sys_ent; 1707 DIR *sys_dir; 1708 1709 if (!strcmp(events_ent->d_name, ".") 1710 || !strcmp(events_ent->d_name, "..") 1711 || !strcmp(events_ent->d_name, "enable") 1712 || !strcmp(events_ent->d_name, "header_event") 1713 || !strcmp(events_ent->d_name, "header_page")) 1714 continue; 1715 1716 sys_path = get_events_file(events_ent->d_name); 1717 TEST_ASSERT_VAL("Can't get sys path", sys_path); 1718 1719 sys_dir = opendir(sys_path); 1720 TEST_ASSERT_VAL("Can't open sys dir", sys_dir); 1721 1722 while ((sys_ent = readdir(sys_dir))) { 1723 if (!strcmp(sys_ent->d_name, ".") 1724 || !strcmp(sys_ent->d_name, "..") 1725 || !strcmp(sys_ent->d_name, "enable") 1726 || !strcmp(sys_ent->d_name, "filter")) 1727 continue; 1728 1729 cnt++; 1730 } 1731 1732 closedir(sys_dir); 1733 put_events_file(sys_path); 1734 } 1735 1736 closedir(events_dir); 1737 return cnt; 1738 } 1739 1740 static int test__all_tracepoints(struct evlist *evlist) 1741 { 1742 TEST_ASSERT_VAL("wrong events count", 1743 count_tracepoints() == evlist->core.nr_entries); 1744 1745 return test__checkevent_tracepoint_multi(evlist); 1746 } 1747 #endif /* HAVE_LIBTRACEVENT */ 1748 1749 struct evlist_test { 1750 const char *name; 1751 bool (*valid)(void); 1752 int (*check)(struct evlist *evlist); 1753 }; 1754 1755 static const struct evlist_test test__events[] = { 1756 #ifdef HAVE_LIBTRACEEVENT 1757 { 1758 .name = "syscalls:sys_enter_openat", 1759 .check = test__checkevent_tracepoint, 1760 /* 0 */ 1761 }, 1762 { 1763 .name = "syscalls:*", 1764 .check = test__checkevent_tracepoint_multi, 1765 /* 1 */ 1766 }, 1767 #endif 1768 { 1769 .name = "r1a", 1770 .check = test__checkevent_raw, 1771 /* 2 */ 1772 }, 1773 { 1774 .name = "1:1", 1775 .check = test__checkevent_numeric, 1776 /* 3 */ 1777 }, 1778 { 1779 .name = "instructions", 1780 .check = test__checkevent_symbolic_name, 1781 /* 4 */ 1782 }, 1783 { 1784 .name = "cycles/period=100000,config2/", 1785 .check = test__checkevent_symbolic_name_config, 1786 /* 5 */ 1787 }, 1788 { 1789 .name = "faults", 1790 .check = test__checkevent_symbolic_alias, 1791 /* 6 */ 1792 }, 1793 { 1794 .name = "L1-dcache-load-miss", 1795 .check = test__checkevent_genhw, 1796 /* 7 */ 1797 }, 1798 { 1799 .name = "mem:0", 1800 .check = test__checkevent_breakpoint, 1801 /* 8 */ 1802 }, 1803 { 1804 .name = "mem:0:x", 1805 .check = test__checkevent_breakpoint_x, 1806 /* 9 */ 1807 }, 1808 { 1809 .name = "mem:0:r", 1810 .check = test__checkevent_breakpoint_r, 1811 /* 0 */ 1812 }, 1813 { 1814 .name = "mem:0:w", 1815 .check = test__checkevent_breakpoint_w, 1816 /* 1 */ 1817 }, 1818 #ifdef HAVE_LIBTRACEEVENT 1819 { 1820 .name = "syscalls:sys_enter_openat:k", 1821 .check = test__checkevent_tracepoint_modifier, 1822 /* 2 */ 1823 }, 1824 { 1825 .name = "syscalls:*:u", 1826 .check = test__checkevent_tracepoint_multi_modifier, 1827 /* 3 */ 1828 }, 1829 #endif 1830 { 1831 .name = "r1a:kp", 1832 .check = test__checkevent_raw_modifier, 1833 /* 4 */ 1834 }, 1835 { 1836 .name = "1:1:hp", 1837 .check = test__checkevent_numeric_modifier, 1838 /* 5 */ 1839 }, 1840 { 1841 .name = "instructions:h", 1842 .check = test__checkevent_symbolic_name_modifier, 1843 /* 6 */ 1844 }, 1845 { 1846 .name = "faults:u", 1847 .check = test__checkevent_symbolic_alias_modifier, 1848 /* 7 */ 1849 }, 1850 { 1851 .name = "L1-dcache-load-miss:kp", 1852 .check = test__checkevent_genhw_modifier, 1853 /* 8 */ 1854 }, 1855 { 1856 .name = "mem:0:u", 1857 .check = test__checkevent_breakpoint_modifier, 1858 /* 9 */ 1859 }, 1860 { 1861 .name = "mem:0:x:k", 1862 .check = test__checkevent_breakpoint_x_modifier, 1863 /* 0 */ 1864 }, 1865 { 1866 .name = "mem:0:r:hp", 1867 .check = test__checkevent_breakpoint_r_modifier, 1868 /* 1 */ 1869 }, 1870 { 1871 .name = "mem:0:w:up", 1872 .check = test__checkevent_breakpoint_w_modifier, 1873 /* 2 */ 1874 }, 1875 #ifdef HAVE_LIBTRACEEVENT 1876 { 1877 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp", 1878 .check = test__checkevent_list, 1879 /* 3 */ 1880 }, 1881 #endif 1882 { 1883 .name = "instructions:G", 1884 .check = test__checkevent_exclude_host_modifier, 1885 /* 4 */ 1886 }, 1887 { 1888 .name = "instructions:H", 1889 .check = test__checkevent_exclude_guest_modifier, 1890 /* 5 */ 1891 }, 1892 { 1893 .name = "mem:0:rw", 1894 .check = test__checkevent_breakpoint_rw, 1895 /* 6 */ 1896 }, 1897 { 1898 .name = "mem:0:rw:kp", 1899 .check = test__checkevent_breakpoint_rw_modifier, 1900 /* 7 */ 1901 }, 1902 { 1903 .name = "{instructions:k,cycles:upp}", 1904 .check = test__group1, 1905 /* 8 */ 1906 }, 1907 { 1908 .name = "{faults:k,cache-references}:u,cycles:k", 1909 .check = test__group2, 1910 /* 9 */ 1911 }, 1912 #ifdef HAVE_LIBTRACEEVENT 1913 { 1914 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u", 1915 .check = test__group3, 1916 /* 0 */ 1917 }, 1918 #endif 1919 { 1920 .name = "{cycles:u,instructions:kp}:p", 1921 .check = test__group4, 1922 /* 1 */ 1923 }, 1924 { 1925 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles", 1926 .check = test__group5, 1927 /* 2 */ 1928 }, 1929 #ifdef HAVE_LIBTRACEEVENT 1930 { 1931 .name = "*:*", 1932 .check = test__all_tracepoints, 1933 /* 3 */ 1934 }, 1935 #endif 1936 { 1937 .name = "{cycles,cache-misses:G}:H", 1938 .check = test__group_gh1, 1939 /* 4 */ 1940 }, 1941 { 1942 .name = "{cycles,cache-misses:H}:G", 1943 .check = test__group_gh2, 1944 /* 5 */ 1945 }, 1946 { 1947 .name = "{cycles:G,cache-misses:H}:u", 1948 .check = test__group_gh3, 1949 /* 6 */ 1950 }, 1951 { 1952 .name = "{cycles:G,cache-misses:H}:uG", 1953 .check = test__group_gh4, 1954 /* 7 */ 1955 }, 1956 { 1957 .name = "{cycles,cache-misses,branch-misses}:S", 1958 .check = test__leader_sample1, 1959 /* 8 */ 1960 }, 1961 { 1962 .name = "{instructions,branch-misses}:Su", 1963 .check = test__leader_sample2, 1964 /* 9 */ 1965 }, 1966 { 1967 .name = "instructions:uDp", 1968 .check = test__checkevent_pinned_modifier, 1969 /* 0 */ 1970 }, 1971 { 1972 .name = "{cycles,cache-misses,branch-misses}:D", 1973 .check = test__pinned_group, 1974 /* 1 */ 1975 }, 1976 { 1977 .name = "mem:0/1", 1978 .check = test__checkevent_breakpoint_len, 1979 /* 2 */ 1980 }, 1981 { 1982 .name = "mem:0/2:w", 1983 .check = test__checkevent_breakpoint_len_w, 1984 /* 3 */ 1985 }, 1986 { 1987 .name = "mem:0/4:rw:u", 1988 .check = test__checkevent_breakpoint_len_rw_modifier, 1989 /* 4 */ 1990 }, 1991 #if defined(__s390x__) && defined(HAVE_LIBTRACEEVENT) 1992 { 1993 .name = "kvm-s390:kvm_s390_create_vm", 1994 .check = test__checkevent_tracepoint, 1995 .valid = kvm_s390_create_vm_valid, 1996 /* 0 */ 1997 }, 1998 #endif 1999 { 2000 .name = "instructions:I", 2001 .check = test__checkevent_exclude_idle_modifier, 2002 /* 5 */ 2003 }, 2004 { 2005 .name = "instructions:kIG", 2006 .check = test__checkevent_exclude_idle_modifier_1, 2007 /* 6 */ 2008 }, 2009 { 2010 .name = "task-clock:P,cycles", 2011 .check = test__checkevent_precise_max_modifier, 2012 /* 7 */ 2013 }, 2014 { 2015 .name = "instructions/name=insn/", 2016 .check = test__checkevent_config_symbol, 2017 /* 8 */ 2018 }, 2019 { 2020 .name = "r1234/name=rawpmu/", 2021 .check = test__checkevent_config_raw, 2022 /* 9 */ 2023 }, 2024 { 2025 .name = "4:0x6530160/name=numpmu/", 2026 .check = test__checkevent_config_num, 2027 /* 0 */ 2028 }, 2029 { 2030 .name = "L1-dcache-misses/name=cachepmu/", 2031 .check = test__checkevent_config_cache, 2032 /* 1 */ 2033 }, 2034 { 2035 .name = "intel_pt//u", 2036 .valid = test__intel_pt_valid, 2037 .check = test__intel_pt, 2038 /* 2 */ 2039 }, 2040 { 2041 .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk", 2042 .check = test__checkevent_complex_name, 2043 /* 3 */ 2044 }, 2045 { 2046 .name = "cycles//u", 2047 .check = test__sym_event_slash, 2048 /* 4 */ 2049 }, 2050 { 2051 .name = "cycles:k", 2052 .check = test__sym_event_dc, 2053 /* 5 */ 2054 }, 2055 { 2056 .name = "instructions:uep", 2057 .check = test__checkevent_exclusive_modifier, 2058 /* 6 */ 2059 }, 2060 { 2061 .name = "{cycles,cache-misses,branch-misses}:e", 2062 .check = test__exclusive_group, 2063 /* 7 */ 2064 }, 2065 { 2066 .name = "cycles/name=name/", 2067 .check = test__term_equal_term, 2068 /* 8 */ 2069 }, 2070 { 2071 .name = "cycles/name=l1d/", 2072 .check = test__term_equal_legacy, 2073 /* 9 */ 2074 }, 2075 { 2076 .name = "mem:0/name=breakpoint/", 2077 .check = test__checkevent_breakpoint, 2078 /* 0 */ 2079 }, 2080 { 2081 .name = "mem:0:x/name=breakpoint/", 2082 .check = test__checkevent_breakpoint_x, 2083 /* 1 */ 2084 }, 2085 { 2086 .name = "mem:0:r/name=breakpoint/", 2087 .check = test__checkevent_breakpoint_r, 2088 /* 2 */ 2089 }, 2090 { 2091 .name = "mem:0:w/name=breakpoint/", 2092 .check = test__checkevent_breakpoint_w, 2093 /* 3 */ 2094 }, 2095 { 2096 .name = "mem:0/name=breakpoint/u", 2097 .check = test__checkevent_breakpoint_modifier_name, 2098 /* 4 */ 2099 }, 2100 { 2101 .name = "mem:0:x/name=breakpoint/k", 2102 .check = test__checkevent_breakpoint_x_modifier_name, 2103 /* 5 */ 2104 }, 2105 { 2106 .name = "mem:0:r/name=breakpoint/hp", 2107 .check = test__checkevent_breakpoint_r_modifier_name, 2108 /* 6 */ 2109 }, 2110 { 2111 .name = "mem:0:w/name=breakpoint/up", 2112 .check = test__checkevent_breakpoint_w_modifier_name, 2113 /* 7 */ 2114 }, 2115 { 2116 .name = "mem:0:rw/name=breakpoint/", 2117 .check = test__checkevent_breakpoint_rw, 2118 /* 8 */ 2119 }, 2120 { 2121 .name = "mem:0:rw/name=breakpoint/kp", 2122 .check = test__checkevent_breakpoint_rw_modifier_name, 2123 /* 9 */ 2124 }, 2125 { 2126 .name = "mem:0/1/name=breakpoint/", 2127 .check = test__checkevent_breakpoint_len, 2128 /* 0 */ 2129 }, 2130 { 2131 .name = "mem:0/2:w/name=breakpoint/", 2132 .check = test__checkevent_breakpoint_len_w, 2133 /* 1 */ 2134 }, 2135 { 2136 .name = "mem:0/4:rw/name=breakpoint/u", 2137 .check = test__checkevent_breakpoint_len_rw_modifier, 2138 /* 2 */ 2139 }, 2140 { 2141 .name = "mem:0/1/name=breakpoint1/,mem:0/4:rw/name=breakpoint2/", 2142 .check = test__checkevent_breakpoint_2_events, 2143 /* 3 */ 2144 }, 2145 }; 2146 2147 static const struct evlist_test test__events_pmu[] = { 2148 { 2149 .name = "cpu/config=10,config1,config2=3,period=1000/u", 2150 .valid = test__pmu_cpu_valid, 2151 .check = test__checkevent_pmu, 2152 /* 0 */ 2153 }, 2154 { 2155 .name = "cpu/config=1,name=krava/u,cpu/config=2/u", 2156 .valid = test__pmu_cpu_valid, 2157 .check = test__checkevent_pmu_name, 2158 /* 1 */ 2159 }, 2160 { 2161 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/", 2162 .valid = test__pmu_cpu_valid, 2163 .check = test__checkevent_pmu_partial_time_callgraph, 2164 /* 2 */ 2165 }, 2166 { 2167 .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp", 2168 .valid = test__pmu_cpu_valid, 2169 .check = test__checkevent_complex_name, 2170 /* 3 */ 2171 }, 2172 { 2173 .name = "software/r1a/", 2174 .check = test__checkevent_raw_pmu, 2175 /* 4 */ 2176 }, 2177 { 2178 .name = "software/r0x1a/", 2179 .check = test__checkevent_raw_pmu, 2180 /* 5 */ 2181 }, 2182 { 2183 .name = "cpu/L1-dcache-load-miss/", 2184 .valid = test__pmu_cpu_valid, 2185 .check = test__checkevent_genhw, 2186 /* 6 */ 2187 }, 2188 { 2189 .name = "cpu/L1-dcache-load-miss/kp", 2190 .valid = test__pmu_cpu_valid, 2191 .check = test__checkevent_genhw_modifier, 2192 /* 7 */ 2193 }, 2194 { 2195 .name = "cpu/L1-dcache-misses,name=cachepmu/", 2196 .valid = test__pmu_cpu_valid, 2197 .check = test__checkevent_config_cache, 2198 /* 8 */ 2199 }, 2200 { 2201 .name = "cpu/instructions/", 2202 .valid = test__pmu_cpu_valid, 2203 .check = test__checkevent_symbolic_name, 2204 /* 9 */ 2205 }, 2206 { 2207 .name = "cpu/cycles,period=100000,config2/", 2208 .valid = test__pmu_cpu_valid, 2209 .check = test__checkevent_symbolic_name_config, 2210 /* 0 */ 2211 }, 2212 { 2213 .name = "cpu/instructions/h", 2214 .valid = test__pmu_cpu_valid, 2215 .check = test__checkevent_symbolic_name_modifier, 2216 /* 1 */ 2217 }, 2218 { 2219 .name = "cpu/instructions/G", 2220 .valid = test__pmu_cpu_valid, 2221 .check = test__checkevent_exclude_host_modifier, 2222 /* 2 */ 2223 }, 2224 { 2225 .name = "cpu/instructions/H", 2226 .valid = test__pmu_cpu_valid, 2227 .check = test__checkevent_exclude_guest_modifier, 2228 /* 3 */ 2229 }, 2230 { 2231 .name = "{cpu/instructions/k,cpu/cycles/upp}", 2232 .valid = test__pmu_cpu_valid, 2233 .check = test__group1, 2234 /* 4 */ 2235 }, 2236 { 2237 .name = "{cpu/cycles/u,cpu/instructions/kp}:p", 2238 .valid = test__pmu_cpu_valid, 2239 .check = test__group4, 2240 /* 5 */ 2241 }, 2242 { 2243 .name = "{cpu/cycles/,cpu/cache-misses/G}:H", 2244 .valid = test__pmu_cpu_valid, 2245 .check = test__group_gh1, 2246 /* 6 */ 2247 }, 2248 { 2249 .name = "{cpu/cycles/,cpu/cache-misses/H}:G", 2250 .valid = test__pmu_cpu_valid, 2251 .check = test__group_gh2, 2252 /* 7 */ 2253 }, 2254 { 2255 .name = "{cpu/cycles/G,cpu/cache-misses/H}:u", 2256 .valid = test__pmu_cpu_valid, 2257 .check = test__group_gh3, 2258 /* 8 */ 2259 }, 2260 { 2261 .name = "{cpu/cycles/G,cpu/cache-misses/H}:uG", 2262 .valid = test__pmu_cpu_valid, 2263 .check = test__group_gh4, 2264 /* 9 */ 2265 }, 2266 { 2267 .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:S", 2268 .valid = test__pmu_cpu_valid, 2269 .check = test__leader_sample1, 2270 /* 0 */ 2271 }, 2272 { 2273 .name = "{cpu/instructions/,cpu/branch-misses/}:Su", 2274 .valid = test__pmu_cpu_valid, 2275 .check = test__leader_sample2, 2276 /* 1 */ 2277 }, 2278 { 2279 .name = "cpu/instructions/uDp", 2280 .valid = test__pmu_cpu_valid, 2281 .check = test__checkevent_pinned_modifier, 2282 /* 2 */ 2283 }, 2284 { 2285 .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:D", 2286 .valid = test__pmu_cpu_valid, 2287 .check = test__pinned_group, 2288 /* 3 */ 2289 }, 2290 { 2291 .name = "cpu/instructions/I", 2292 .valid = test__pmu_cpu_valid, 2293 .check = test__checkevent_exclude_idle_modifier, 2294 /* 4 */ 2295 }, 2296 { 2297 .name = "cpu/instructions/kIG", 2298 .valid = test__pmu_cpu_valid, 2299 .check = test__checkevent_exclude_idle_modifier_1, 2300 /* 5 */ 2301 }, 2302 { 2303 .name = "cpu/cycles/u", 2304 .valid = test__pmu_cpu_valid, 2305 .check = test__sym_event_slash, 2306 /* 6 */ 2307 }, 2308 { 2309 .name = "cpu/cycles/k", 2310 .valid = test__pmu_cpu_valid, 2311 .check = test__sym_event_dc, 2312 /* 7 */ 2313 }, 2314 { 2315 .name = "cpu/instructions/uep", 2316 .valid = test__pmu_cpu_valid, 2317 .check = test__checkevent_exclusive_modifier, 2318 /* 8 */ 2319 }, 2320 { 2321 .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:e", 2322 .valid = test__pmu_cpu_valid, 2323 .check = test__exclusive_group, 2324 /* 9 */ 2325 }, 2326 { 2327 .name = "cpu/cycles,name=name/", 2328 .valid = test__pmu_cpu_valid, 2329 .check = test__term_equal_term, 2330 /* 0 */ 2331 }, 2332 { 2333 .name = "cpu/cycles,name=l1d/", 2334 .valid = test__pmu_cpu_valid, 2335 .check = test__term_equal_legacy, 2336 /* 1 */ 2337 }, 2338 }; 2339 2340 struct terms_test { 2341 const char *str; 2342 int (*check)(struct list_head *terms); 2343 }; 2344 2345 static const struct terms_test test__terms[] = { 2346 [0] = { 2347 .str = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead", 2348 .check = test__checkterms_simple, 2349 }, 2350 }; 2351 2352 static int test_event(const struct evlist_test *e) 2353 { 2354 struct parse_events_error err; 2355 struct evlist *evlist; 2356 int ret; 2357 2358 if (e->valid && !e->valid()) { 2359 pr_debug("... SKIP\n"); 2360 return TEST_OK; 2361 } 2362 2363 evlist = evlist__new(); 2364 if (evlist == NULL) { 2365 pr_err("Failed allocation"); 2366 return TEST_FAIL; 2367 } 2368 parse_events_error__init(&err); 2369 ret = parse_events(evlist, e->name, &err); 2370 if (ret) { 2371 pr_debug("failed to parse event '%s', err %d, str '%s'\n", 2372 e->name, ret, err.str); 2373 parse_events_error__print(&err, e->name); 2374 ret = TEST_FAIL; 2375 if (err.str && strstr(err.str, "can't access trace events")) 2376 ret = TEST_SKIP; 2377 } else { 2378 ret = e->check(evlist); 2379 } 2380 parse_events_error__exit(&err); 2381 evlist__delete(evlist); 2382 2383 return ret; 2384 } 2385 2386 static int test_event_fake_pmu(const char *str) 2387 { 2388 struct parse_events_error err; 2389 struct evlist *evlist; 2390 int ret; 2391 2392 evlist = evlist__new(); 2393 if (!evlist) 2394 return -ENOMEM; 2395 2396 parse_events_error__init(&err); 2397 ret = __parse_events(evlist, str, /*pmu_filter=*/NULL, &err, 2398 &perf_pmu__fake, /*warn_if_reordered=*/true); 2399 if (ret) { 2400 pr_debug("failed to parse event '%s', err %d, str '%s'\n", 2401 str, ret, err.str); 2402 parse_events_error__print(&err, str); 2403 } 2404 2405 parse_events_error__exit(&err); 2406 evlist__delete(evlist); 2407 2408 return ret; 2409 } 2410 2411 static int combine_test_results(int existing, int latest) 2412 { 2413 if (existing == TEST_FAIL) 2414 return TEST_FAIL; 2415 if (existing == TEST_SKIP) 2416 return latest == TEST_OK ? TEST_SKIP : latest; 2417 return latest; 2418 } 2419 2420 static int test_events(const struct evlist_test *events, int cnt) 2421 { 2422 int ret = TEST_OK; 2423 2424 for (int i = 0; i < cnt; i++) { 2425 const struct evlist_test *e = &events[i]; 2426 int test_ret; 2427 2428 pr_debug("running test %d '%s'\n", i, e->name); 2429 test_ret = test_event(e); 2430 if (test_ret != TEST_OK) { 2431 pr_debug("Event test failure: test %d '%s'", i, e->name); 2432 ret = combine_test_results(ret, test_ret); 2433 } 2434 } 2435 2436 return ret; 2437 } 2438 2439 static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2440 { 2441 return test_events(test__events, ARRAY_SIZE(test__events)); 2442 } 2443 2444 static int test_term(const struct terms_test *t) 2445 { 2446 struct list_head terms; 2447 int ret; 2448 2449 INIT_LIST_HEAD(&terms); 2450 2451 ret = parse_events_terms(&terms, t->str); 2452 if (ret) { 2453 pr_debug("failed to parse terms '%s', err %d\n", 2454 t->str , ret); 2455 return ret; 2456 } 2457 2458 ret = t->check(&terms); 2459 parse_events_terms__purge(&terms); 2460 2461 return ret; 2462 } 2463 2464 static int test_terms(const struct terms_test *terms, int cnt) 2465 { 2466 int ret = 0; 2467 2468 for (int i = 0; i < cnt; i++) { 2469 const struct terms_test *t = &terms[i]; 2470 2471 pr_debug("running test %d '%s'\n", i, t->str); 2472 ret = test_term(t); 2473 if (ret) 2474 break; 2475 } 2476 2477 return ret; 2478 } 2479 2480 static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2481 { 2482 return test_terms(test__terms, ARRAY_SIZE(test__terms)); 2483 } 2484 2485 static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2486 { 2487 struct perf_pmu *pmu = NULL; 2488 int ret = TEST_OK; 2489 2490 while ((pmu = perf_pmus__scan(pmu)) != NULL) { 2491 struct stat st; 2492 char path[PATH_MAX]; 2493 struct dirent *ent; 2494 DIR *dir; 2495 int err; 2496 2497 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/", 2498 sysfs__mountpoint(), pmu->name); 2499 2500 err = stat(path, &st); 2501 if (err) { 2502 pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path); 2503 continue; 2504 } 2505 2506 dir = opendir(path); 2507 if (!dir) { 2508 pr_debug("can't open pmu event dir: %s\n", path); 2509 ret = combine_test_results(ret, TEST_SKIP); 2510 continue; 2511 } 2512 2513 while ((ent = readdir(dir))) { 2514 struct evlist_test e = { .name = NULL, }; 2515 char name[2 * NAME_MAX + 1 + 12 + 3]; 2516 int test_ret; 2517 2518 /* Names containing . are special and cannot be used directly */ 2519 if (strchr(ent->d_name, '.')) 2520 continue; 2521 2522 snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name); 2523 2524 e.name = name; 2525 e.check = test__checkevent_pmu_events; 2526 2527 test_ret = test_event(&e); 2528 if (test_ret != TEST_OK) { 2529 pr_debug("Test PMU event failed for '%s'", name); 2530 ret = combine_test_results(ret, test_ret); 2531 } 2532 2533 if (!is_pmu_core(pmu->name)) 2534 continue; 2535 2536 /* 2537 * Names containing '-' are recognized as prefixes and suffixes 2538 * due to '-' being a legacy PMU separator. This fails when the 2539 * prefix or suffix collides with an existing legacy token. For 2540 * example, branch-brs has a prefix (branch) that collides with 2541 * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix 2542 * isn't expected after this. As event names in the config 2543 * slashes are allowed a '-' in the name we check this works 2544 * above. 2545 */ 2546 if (strchr(ent->d_name, '-')) 2547 continue; 2548 2549 snprintf(name, sizeof(name), "%s:u,%s/event=%s/u", 2550 ent->d_name, pmu->name, ent->d_name); 2551 e.name = name; 2552 e.check = test__checkevent_pmu_events_mix; 2553 test_ret = test_event(&e); 2554 if (test_ret != TEST_OK) { 2555 pr_debug("Test PMU event failed for '%s'", name); 2556 ret = combine_test_results(ret, test_ret); 2557 } 2558 } 2559 2560 closedir(dir); 2561 } 2562 return ret; 2563 } 2564 2565 static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2566 { 2567 return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu)); 2568 } 2569 2570 static bool test_alias(char **event, char **alias) 2571 { 2572 char path[PATH_MAX]; 2573 DIR *dir; 2574 struct dirent *dent; 2575 const char *sysfs = sysfs__mountpoint(); 2576 char buf[128]; 2577 FILE *file; 2578 2579 if (!sysfs) 2580 return false; 2581 2582 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs); 2583 dir = opendir(path); 2584 if (!dir) 2585 return false; 2586 2587 while ((dent = readdir(dir))) { 2588 if (!strcmp(dent->d_name, ".") || 2589 !strcmp(dent->d_name, "..")) 2590 continue; 2591 2592 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias", 2593 sysfs, dent->d_name); 2594 2595 if (!file_available(path)) 2596 continue; 2597 2598 file = fopen(path, "r"); 2599 if (!file) 2600 continue; 2601 2602 if (!fgets(buf, sizeof(buf), file)) { 2603 fclose(file); 2604 continue; 2605 } 2606 2607 /* Remove the last '\n' */ 2608 buf[strlen(buf) - 1] = 0; 2609 2610 fclose(file); 2611 *event = strdup(dent->d_name); 2612 *alias = strdup(buf); 2613 closedir(dir); 2614 2615 if (*event == NULL || *alias == NULL) { 2616 free(*event); 2617 free(*alias); 2618 return false; 2619 } 2620 2621 return true; 2622 } 2623 2624 closedir(dir); 2625 return false; 2626 } 2627 2628 static int test__checkevent_pmu_events_alias(struct evlist *evlist) 2629 { 2630 struct evsel *evsel1 = evlist__first(evlist); 2631 struct evsel *evsel2 = evlist__last(evlist); 2632 2633 TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type); 2634 TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config); 2635 return TEST_OK; 2636 } 2637 2638 static int test__pmu_events_alias(char *event, char *alias) 2639 { 2640 struct evlist_test e = { .name = NULL, }; 2641 char name[2 * NAME_MAX + 20]; 2642 2643 snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/", 2644 event, alias); 2645 2646 e.name = name; 2647 e.check = test__checkevent_pmu_events_alias; 2648 return test_event(&e); 2649 } 2650 2651 static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2652 { 2653 char *event, *alias; 2654 int ret; 2655 2656 if (!test_alias(&event, &alias)) 2657 return TEST_SKIP; 2658 2659 ret = test__pmu_events_alias(event, alias); 2660 2661 free(event); 2662 free(alias); 2663 return ret; 2664 } 2665 2666 static int test__pmu_events_alias2(struct test_suite *test __maybe_unused, 2667 int subtest __maybe_unused) 2668 { 2669 static const char events[][30] = { 2670 "event-hyphen", 2671 "event-two-hyph", 2672 }; 2673 int ret = TEST_OK; 2674 2675 for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) { 2676 int test_ret = test_event_fake_pmu(&events[i][0]); 2677 2678 if (test_ret != TEST_OK) { 2679 pr_debug("check_parse_fake %s failed\n", &events[i][0]); 2680 ret = combine_test_results(ret, test_ret); 2681 } 2682 } 2683 2684 return ret; 2685 } 2686 2687 static struct test_case tests__parse_events[] = { 2688 TEST_CASE_REASON("Test event parsing", 2689 events2, 2690 "permissions"), 2691 TEST_CASE_REASON("Parsing of all PMU events from sysfs", 2692 pmu_events, 2693 "permissions"), 2694 TEST_CASE_REASON("Parsing of given PMU events from sysfs", 2695 pmu_events2, 2696 "permissions"), 2697 TEST_CASE_REASON("Parsing of aliased events from sysfs", alias, 2698 "no aliases in sysfs"), 2699 TEST_CASE("Parsing of aliased events", pmu_events_alias2), 2700 TEST_CASE("Parsing of terms (event modifiers)", terms2), 2701 { .name = NULL, } 2702 }; 2703 2704 struct test_suite suite__parse_events = { 2705 .desc = "Parse event definition strings", 2706 .test_cases = tests__parse_events, 2707 }; 2708