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