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