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