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