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