1 #include "parse-events.h" 2 #include "evsel.h" 3 #include "evlist.h" 4 #include <api/fs/fs.h> 5 #include "tests.h" 6 #include "debug.h" 7 #include "util.h" 8 #include <errno.h> 9 #include <linux/kernel.h> 10 #include <linux/hw_breakpoint.h> 11 #include <api/fs/fs.h> 12 #include <api/fs/tracing_path.h> 13 14 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ 15 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) 16 17 static int test__checkevent_tracepoint(struct perf_evlist *evlist) 18 { 19 struct perf_evsel *evsel = perf_evlist__first(evlist); 20 21 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 22 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups); 23 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); 24 TEST_ASSERT_VAL("wrong sample_type", 25 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); 26 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); 27 return 0; 28 } 29 30 static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist) 31 { 32 struct perf_evsel *evsel; 33 34 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); 35 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups); 36 37 evlist__for_each_entry(evlist, evsel) { 38 TEST_ASSERT_VAL("wrong type", 39 PERF_TYPE_TRACEPOINT == evsel->attr.type); 40 TEST_ASSERT_VAL("wrong sample_type", 41 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); 42 TEST_ASSERT_VAL("wrong sample_period", 43 1 == evsel->attr.sample_period); 44 } 45 return 0; 46 } 47 48 static int test__checkevent_raw(struct perf_evlist *evlist) 49 { 50 struct perf_evsel *evsel = perf_evlist__first(evlist); 51 52 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 53 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 54 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config); 55 return 0; 56 } 57 58 static int test__checkevent_numeric(struct perf_evlist *evlist) 59 { 60 struct perf_evsel *evsel = perf_evlist__first(evlist); 61 62 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 63 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); 64 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); 65 return 0; 66 } 67 68 static int test__checkevent_symbolic_name(struct perf_evlist *evlist) 69 { 70 struct perf_evsel *evsel = perf_evlist__first(evlist); 71 72 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 73 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 74 TEST_ASSERT_VAL("wrong config", 75 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 76 return 0; 77 } 78 79 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist) 80 { 81 struct perf_evsel *evsel = perf_evlist__first(evlist); 82 83 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 84 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 85 TEST_ASSERT_VAL("wrong config", 86 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 87 /* 88 * The period value gets configured within perf_evlist__config, 89 * while this test executes only parse events method. 90 */ 91 TEST_ASSERT_VAL("wrong period", 92 0 == evsel->attr.sample_period); 93 TEST_ASSERT_VAL("wrong config1", 94 0 == evsel->attr.config1); 95 TEST_ASSERT_VAL("wrong config2", 96 1 == evsel->attr.config2); 97 return 0; 98 } 99 100 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist) 101 { 102 struct perf_evsel *evsel = perf_evlist__first(evlist); 103 104 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 105 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); 106 TEST_ASSERT_VAL("wrong config", 107 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config); 108 return 0; 109 } 110 111 static int test__checkevent_genhw(struct perf_evlist *evlist) 112 { 113 struct perf_evsel *evsel = perf_evlist__first(evlist); 114 115 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 116 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type); 117 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config); 118 return 0; 119 } 120 121 static int test__checkevent_breakpoint(struct perf_evlist *evlist) 122 { 123 struct perf_evsel *evsel = perf_evlist__first(evlist); 124 125 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 126 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); 127 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 128 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == 129 evsel->attr.bp_type); 130 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 == 131 evsel->attr.bp_len); 132 return 0; 133 } 134 135 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist) 136 { 137 struct perf_evsel *evsel = perf_evlist__first(evlist); 138 139 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 140 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); 141 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 142 TEST_ASSERT_VAL("wrong bp_type", 143 HW_BREAKPOINT_X == evsel->attr.bp_type); 144 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len); 145 return 0; 146 } 147 148 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist) 149 { 150 struct perf_evsel *evsel = perf_evlist__first(evlist); 151 152 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 153 TEST_ASSERT_VAL("wrong type", 154 PERF_TYPE_BREAKPOINT == evsel->attr.type); 155 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 156 TEST_ASSERT_VAL("wrong bp_type", 157 HW_BREAKPOINT_R == evsel->attr.bp_type); 158 TEST_ASSERT_VAL("wrong bp_len", 159 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); 160 return 0; 161 } 162 163 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist) 164 { 165 struct perf_evsel *evsel = perf_evlist__first(evlist); 166 167 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 168 TEST_ASSERT_VAL("wrong type", 169 PERF_TYPE_BREAKPOINT == evsel->attr.type); 170 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 171 TEST_ASSERT_VAL("wrong bp_type", 172 HW_BREAKPOINT_W == evsel->attr.bp_type); 173 TEST_ASSERT_VAL("wrong bp_len", 174 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); 175 return 0; 176 } 177 178 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist) 179 { 180 struct perf_evsel *evsel = perf_evlist__first(evlist); 181 182 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 183 TEST_ASSERT_VAL("wrong type", 184 PERF_TYPE_BREAKPOINT == evsel->attr.type); 185 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 186 TEST_ASSERT_VAL("wrong bp_type", 187 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type); 188 TEST_ASSERT_VAL("wrong bp_len", 189 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); 190 return 0; 191 } 192 193 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist) 194 { 195 struct perf_evsel *evsel = perf_evlist__first(evlist); 196 197 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 198 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 199 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 200 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 201 202 return test__checkevent_tracepoint(evlist); 203 } 204 205 static int 206 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist) 207 { 208 struct perf_evsel *evsel; 209 210 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); 211 212 evlist__for_each_entry(evlist, evsel) { 213 TEST_ASSERT_VAL("wrong exclude_user", 214 !evsel->attr.exclude_user); 215 TEST_ASSERT_VAL("wrong exclude_kernel", 216 evsel->attr.exclude_kernel); 217 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 218 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 219 } 220 221 return test__checkevent_tracepoint_multi(evlist); 222 } 223 224 static int test__checkevent_raw_modifier(struct perf_evlist *evlist) 225 { 226 struct perf_evsel *evsel = perf_evlist__first(evlist); 227 228 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 229 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 230 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 231 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 232 233 return test__checkevent_raw(evlist); 234 } 235 236 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist) 237 { 238 struct perf_evsel *evsel = perf_evlist__first(evlist); 239 240 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 241 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 242 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 243 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 244 245 return test__checkevent_numeric(evlist); 246 } 247 248 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist) 249 { 250 struct perf_evsel *evsel = perf_evlist__first(evlist); 251 252 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 253 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 254 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 255 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 256 257 return test__checkevent_symbolic_name(evlist); 258 } 259 260 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist) 261 { 262 struct perf_evsel *evsel = perf_evlist__first(evlist); 263 264 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 265 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 266 267 return test__checkevent_symbolic_name(evlist); 268 } 269 270 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist) 271 { 272 struct perf_evsel *evsel = perf_evlist__first(evlist); 273 274 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 275 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 276 277 return test__checkevent_symbolic_name(evlist); 278 } 279 280 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist) 281 { 282 struct perf_evsel *evsel = perf_evlist__first(evlist); 283 284 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 285 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 286 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 287 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 288 289 return test__checkevent_symbolic_alias(evlist); 290 } 291 292 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist) 293 { 294 struct perf_evsel *evsel = perf_evlist__first(evlist); 295 296 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 297 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 298 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 299 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 300 301 return test__checkevent_genhw(evlist); 302 } 303 304 static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist) 305 { 306 struct perf_evsel *evsel = perf_evlist__first(evlist); 307 308 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle); 309 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 310 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 311 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 312 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 313 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 314 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 315 316 return test__checkevent_symbolic_name(evlist); 317 } 318 319 static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist) 320 { 321 struct perf_evsel *evsel = perf_evlist__first(evlist); 322 323 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle); 324 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 325 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 326 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 327 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 328 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 329 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 330 331 return test__checkevent_symbolic_name(evlist); 332 } 333 334 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist) 335 { 336 struct perf_evsel *evsel = perf_evlist__first(evlist); 337 338 339 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 340 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 341 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 342 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 343 TEST_ASSERT_VAL("wrong name", 344 !strcmp(perf_evsel__name(evsel), "mem:0:u")); 345 346 return test__checkevent_breakpoint(evlist); 347 } 348 349 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist) 350 { 351 struct perf_evsel *evsel = perf_evlist__first(evlist); 352 353 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 354 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 355 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 356 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 357 TEST_ASSERT_VAL("wrong name", 358 !strcmp(perf_evsel__name(evsel), "mem:0:x:k")); 359 360 return test__checkevent_breakpoint_x(evlist); 361 } 362 363 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist) 364 { 365 struct perf_evsel *evsel = perf_evlist__first(evlist); 366 367 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 368 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 369 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 370 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 371 TEST_ASSERT_VAL("wrong name", 372 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp")); 373 374 return test__checkevent_breakpoint_r(evlist); 375 } 376 377 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist) 378 { 379 struct perf_evsel *evsel = perf_evlist__first(evlist); 380 381 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 382 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 383 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 384 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 385 TEST_ASSERT_VAL("wrong name", 386 !strcmp(perf_evsel__name(evsel), "mem:0:w:up")); 387 388 return test__checkevent_breakpoint_w(evlist); 389 } 390 391 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist) 392 { 393 struct perf_evsel *evsel = perf_evlist__first(evlist); 394 395 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 396 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 397 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 398 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 399 TEST_ASSERT_VAL("wrong name", 400 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp")); 401 402 return test__checkevent_breakpoint_rw(evlist); 403 } 404 405 static int test__checkevent_pmu(struct perf_evlist *evlist) 406 { 407 408 struct perf_evsel *evsel = perf_evlist__first(evlist); 409 410 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 411 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 412 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config); 413 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1); 414 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2); 415 /* 416 * The period value gets configured within perf_evlist__config, 417 * while this test executes only parse events method. 418 */ 419 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); 420 421 return 0; 422 } 423 424 static int test__checkevent_list(struct perf_evlist *evlist) 425 { 426 struct perf_evsel *evsel = perf_evlist__first(evlist); 427 428 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); 429 430 /* r1 */ 431 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 432 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); 433 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1); 434 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2); 435 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 436 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 437 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 438 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 439 440 /* syscalls:sys_enter_openat:k */ 441 evsel = perf_evsel__next(evsel); 442 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); 443 TEST_ASSERT_VAL("wrong sample_type", 444 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); 445 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); 446 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 447 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 448 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 449 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 450 451 /* 1:1:hp */ 452 evsel = perf_evsel__next(evsel); 453 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); 454 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); 455 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 456 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 457 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 458 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 459 460 return 0; 461 } 462 463 static int test__checkevent_pmu_name(struct perf_evlist *evlist) 464 { 465 struct perf_evsel *evsel = perf_evlist__first(evlist); 466 467 /* cpu/config=1,name=krava/u */ 468 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 469 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 470 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); 471 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava")); 472 473 /* cpu/config=2/u" */ 474 evsel = perf_evsel__next(evsel); 475 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 476 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 477 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config); 478 TEST_ASSERT_VAL("wrong name", 479 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u")); 480 481 return 0; 482 } 483 484 static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist) 485 { 486 struct perf_evsel *evsel = perf_evlist__first(evlist); 487 488 /* cpu/config=1,call-graph=fp,time,period=100000/ */ 489 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 490 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 491 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); 492 /* 493 * The period, time and callgraph value gets configured 494 * within perf_evlist__config, 495 * while this test executes only parse events method. 496 */ 497 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); 498 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type)); 499 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type)); 500 501 /* cpu/config=2,call-graph=no,time=0,period=2000/ */ 502 evsel = perf_evsel__next(evsel); 503 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 504 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config); 505 /* 506 * The period, time and callgraph value gets configured 507 * within perf_evlist__config, 508 * while this test executes only parse events method. 509 */ 510 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period); 511 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type)); 512 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type)); 513 514 return 0; 515 } 516 517 static int test__checkevent_pmu_events(struct perf_evlist *evlist) 518 { 519 struct perf_evsel *evsel = perf_evlist__first(evlist); 520 521 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 522 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 523 TEST_ASSERT_VAL("wrong exclude_user", 524 !evsel->attr.exclude_user); 525 TEST_ASSERT_VAL("wrong exclude_kernel", 526 evsel->attr.exclude_kernel); 527 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 528 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 529 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned); 530 531 return 0; 532 } 533 534 535 static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist) 536 { 537 struct perf_evsel *evsel = perf_evlist__first(evlist); 538 539 /* pmu-event:u */ 540 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 541 TEST_ASSERT_VAL("wrong exclude_user", 542 !evsel->attr.exclude_user); 543 TEST_ASSERT_VAL("wrong exclude_kernel", 544 evsel->attr.exclude_kernel); 545 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 546 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 547 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned); 548 549 /* cpu/pmu-event/u*/ 550 evsel = perf_evsel__next(evsel); 551 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 552 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); 553 TEST_ASSERT_VAL("wrong exclude_user", 554 !evsel->attr.exclude_user); 555 TEST_ASSERT_VAL("wrong exclude_kernel", 556 evsel->attr.exclude_kernel); 557 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 558 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 559 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned); 560 561 return 0; 562 } 563 564 static int test__checkterms_simple(struct list_head *terms) 565 { 566 struct parse_events_term *term; 567 568 /* config=10 */ 569 term = list_entry(terms->next, struct parse_events_term, list); 570 TEST_ASSERT_VAL("wrong type term", 571 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG); 572 TEST_ASSERT_VAL("wrong type val", 573 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 574 TEST_ASSERT_VAL("wrong val", term->val.num == 10); 575 TEST_ASSERT_VAL("wrong config", !term->config); 576 577 /* config1 */ 578 term = list_entry(term->list.next, struct parse_events_term, list); 579 TEST_ASSERT_VAL("wrong type term", 580 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1); 581 TEST_ASSERT_VAL("wrong type val", 582 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 583 TEST_ASSERT_VAL("wrong val", term->val.num == 1); 584 TEST_ASSERT_VAL("wrong config", !term->config); 585 586 /* config2=3 */ 587 term = list_entry(term->list.next, struct parse_events_term, list); 588 TEST_ASSERT_VAL("wrong type term", 589 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2); 590 TEST_ASSERT_VAL("wrong type val", 591 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 592 TEST_ASSERT_VAL("wrong val", term->val.num == 3); 593 TEST_ASSERT_VAL("wrong config", !term->config); 594 595 /* umask=1*/ 596 term = list_entry(term->list.next, struct parse_events_term, list); 597 TEST_ASSERT_VAL("wrong type term", 598 term->type_term == PARSE_EVENTS__TERM_TYPE_USER); 599 TEST_ASSERT_VAL("wrong type val", 600 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM); 601 TEST_ASSERT_VAL("wrong val", term->val.num == 1); 602 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask")); 603 604 return 0; 605 } 606 607 static int test__group1(struct perf_evlist *evlist) 608 { 609 struct perf_evsel *evsel, *leader; 610 611 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 612 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 613 614 /* instructions:k */ 615 evsel = leader = perf_evlist__first(evlist); 616 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 617 TEST_ASSERT_VAL("wrong config", 618 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 619 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 620 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 621 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 622 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 623 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 624 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 625 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 626 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 627 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 628 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 629 630 /* cycles:upp */ 631 evsel = perf_evsel__next(evsel); 632 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 633 TEST_ASSERT_VAL("wrong config", 634 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 635 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 636 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 637 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 638 /* use of precise requires exclude_guest */ 639 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 640 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 641 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2); 642 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 643 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 644 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 645 646 return 0; 647 } 648 649 static int test__group2(struct perf_evlist *evlist) 650 { 651 struct perf_evsel *evsel, *leader; 652 653 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); 654 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 655 656 /* faults + :ku modifier */ 657 evsel = leader = perf_evlist__first(evlist); 658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); 659 TEST_ASSERT_VAL("wrong config", 660 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config); 661 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 662 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 663 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 664 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 665 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 666 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 667 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 668 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 669 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 670 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 671 672 /* cache-references + :u modifier */ 673 evsel = perf_evsel__next(evsel); 674 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 675 TEST_ASSERT_VAL("wrong config", 676 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config); 677 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 678 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 679 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 680 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 681 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 682 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 683 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 684 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 685 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 686 687 /* cycles:k */ 688 evsel = perf_evsel__next(evsel); 689 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 690 TEST_ASSERT_VAL("wrong config", 691 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 692 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 693 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 694 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 695 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 696 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 697 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 698 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 699 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 700 701 return 0; 702 } 703 704 static int test__group3(struct perf_evlist *evlist __maybe_unused) 705 { 706 struct perf_evsel *evsel, *leader; 707 708 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries); 709 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups); 710 711 /* group1 syscalls:sys_enter_openat:H */ 712 evsel = leader = perf_evlist__first(evlist); 713 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); 714 TEST_ASSERT_VAL("wrong sample_type", 715 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type); 716 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); 717 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 718 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 719 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 720 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 721 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 722 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 723 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 724 TEST_ASSERT_VAL("wrong group name", 725 !strcmp(leader->group_name, "group1")); 726 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 727 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 728 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 729 730 /* group1 cycles:kppp */ 731 evsel = perf_evsel__next(evsel); 732 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 733 TEST_ASSERT_VAL("wrong config", 734 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 735 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 736 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 737 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 738 /* use of precise requires exclude_guest */ 739 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 740 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 741 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3); 742 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 743 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 744 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 745 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 746 747 /* group2 cycles + G modifier */ 748 evsel = leader = perf_evsel__next(evsel); 749 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 750 TEST_ASSERT_VAL("wrong config", 751 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 752 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 753 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 754 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 755 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 756 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 757 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 758 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 759 TEST_ASSERT_VAL("wrong group name", 760 !strcmp(leader->group_name, "group2")); 761 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 762 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 763 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 764 765 /* group2 1:3 + G modifier */ 766 evsel = perf_evsel__next(evsel); 767 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); 768 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config); 769 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 770 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 771 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 772 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 773 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 774 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 775 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 776 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 777 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 778 779 /* instructions:u */ 780 evsel = perf_evsel__next(evsel); 781 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 782 TEST_ASSERT_VAL("wrong config", 783 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 784 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 785 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 786 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 787 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 788 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 789 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 790 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 791 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 792 793 return 0; 794 } 795 796 static int test__group4(struct perf_evlist *evlist __maybe_unused) 797 { 798 struct perf_evsel *evsel, *leader; 799 800 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 801 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 802 803 /* cycles:u + p */ 804 evsel = leader = perf_evlist__first(evlist); 805 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 806 TEST_ASSERT_VAL("wrong config", 807 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 808 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 809 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 810 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 811 /* use of precise requires exclude_guest */ 812 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 813 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 814 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1); 815 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 816 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 817 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 818 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 819 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 820 821 /* instructions:kp + p */ 822 evsel = perf_evsel__next(evsel); 823 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 824 TEST_ASSERT_VAL("wrong config", 825 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 826 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); 827 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 828 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 829 /* use of precise requires exclude_guest */ 830 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 831 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 832 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2); 833 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 834 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 835 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 836 837 return 0; 838 } 839 840 static int test__group5(struct perf_evlist *evlist __maybe_unused) 841 { 842 struct perf_evsel *evsel, *leader; 843 844 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries); 845 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups); 846 847 /* cycles + G */ 848 evsel = leader = perf_evlist__first(evlist); 849 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 850 TEST_ASSERT_VAL("wrong config", 851 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 852 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 853 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 854 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 855 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 856 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 857 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 858 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 859 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 860 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 861 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 862 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 863 864 /* instructions + G */ 865 evsel = perf_evsel__next(evsel); 866 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 867 TEST_ASSERT_VAL("wrong config", 868 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 869 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 870 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 871 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 872 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 873 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 874 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 875 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 876 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 877 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 878 879 /* cycles:G */ 880 evsel = leader = perf_evsel__next(evsel); 881 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 882 TEST_ASSERT_VAL("wrong config", 883 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 884 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 885 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 886 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 887 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 888 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 889 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 890 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 891 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 892 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 893 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 894 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); 895 896 /* instructions:G */ 897 evsel = perf_evsel__next(evsel); 898 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 899 TEST_ASSERT_VAL("wrong config", 900 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 901 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 902 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 903 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 904 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 905 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 906 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 907 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 908 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 909 910 /* cycles */ 911 evsel = perf_evsel__next(evsel); 912 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 913 TEST_ASSERT_VAL("wrong config", 914 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 915 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 916 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 917 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 918 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 919 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 920 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 921 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 922 923 return 0; 924 } 925 926 static int test__group_gh1(struct perf_evlist *evlist) 927 { 928 struct perf_evsel *evsel, *leader; 929 930 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 931 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 932 933 /* cycles + :H group modifier */ 934 evsel = leader = perf_evlist__first(evlist); 935 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 936 TEST_ASSERT_VAL("wrong config", 937 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 938 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 939 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 940 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 941 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 942 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 943 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 944 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 945 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 946 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 947 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 948 949 /* cache-misses:G + :H group modifier */ 950 evsel = perf_evsel__next(evsel); 951 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 952 TEST_ASSERT_VAL("wrong config", 953 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); 954 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 955 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 956 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 957 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 958 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 959 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 960 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 961 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 962 963 return 0; 964 } 965 966 static int test__group_gh2(struct perf_evlist *evlist) 967 { 968 struct perf_evsel *evsel, *leader; 969 970 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 971 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 972 973 /* cycles + :G group modifier */ 974 evsel = leader = perf_evlist__first(evlist); 975 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 976 TEST_ASSERT_VAL("wrong config", 977 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 978 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 979 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 980 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 981 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 982 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 983 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 984 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 985 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 986 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 987 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 988 989 /* cache-misses:H + :G group modifier */ 990 evsel = perf_evsel__next(evsel); 991 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 992 TEST_ASSERT_VAL("wrong config", 993 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); 994 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 995 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 996 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 997 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 998 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 999 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1000 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1001 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 1002 1003 return 0; 1004 } 1005 1006 static int test__group_gh3(struct perf_evlist *evlist) 1007 { 1008 struct perf_evsel *evsel, *leader; 1009 1010 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 1011 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 1012 1013 /* cycles:G + :u group modifier */ 1014 evsel = leader = perf_evlist__first(evlist); 1015 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1016 TEST_ASSERT_VAL("wrong config", 1017 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 1018 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1019 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1020 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1021 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 1022 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 1023 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1024 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1025 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 1026 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 1027 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 1028 1029 /* cache-misses:H + :u group modifier */ 1030 evsel = perf_evsel__next(evsel); 1031 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1032 TEST_ASSERT_VAL("wrong config", 1033 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); 1034 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1035 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1036 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1037 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 1038 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1039 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1040 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1041 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 1042 1043 return 0; 1044 } 1045 1046 static int test__group_gh4(struct perf_evlist *evlist) 1047 { 1048 struct perf_evsel *evsel, *leader; 1049 1050 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 1051 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups); 1052 1053 /* cycles:G + :uG group modifier */ 1054 evsel = leader = perf_evlist__first(evlist); 1055 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1056 TEST_ASSERT_VAL("wrong config", 1057 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 1058 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1059 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1060 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1061 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 1062 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); 1063 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1064 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1065 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel)); 1066 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2); 1067 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0); 1068 1069 /* cache-misses:H + :uG group modifier */ 1070 evsel = perf_evsel__next(evsel); 1071 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1072 TEST_ASSERT_VAL("wrong config", 1073 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); 1074 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1075 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1076 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1077 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); 1078 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1079 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1080 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1081 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1); 1082 1083 return 0; 1084 } 1085 1086 static int test__leader_sample1(struct perf_evlist *evlist) 1087 { 1088 struct perf_evsel *evsel, *leader; 1089 1090 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); 1091 1092 /* cycles - sampling group leader */ 1093 evsel = leader = perf_evlist__first(evlist); 1094 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1095 TEST_ASSERT_VAL("wrong config", 1096 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 1097 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1098 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 1099 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 1100 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 1101 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1102 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1103 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1104 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1105 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1106 1107 /* cache-misses - not sampling */ 1108 evsel = perf_evsel__next(evsel); 1109 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1110 TEST_ASSERT_VAL("wrong config", 1111 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); 1112 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1113 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 1114 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 1115 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 1116 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1117 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1118 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1119 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1120 1121 /* branch-misses - not sampling */ 1122 evsel = perf_evsel__next(evsel); 1123 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1124 TEST_ASSERT_VAL("wrong config", 1125 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config); 1126 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1127 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); 1128 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); 1129 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 1130 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1131 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1132 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1133 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1134 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1135 1136 return 0; 1137 } 1138 1139 static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused) 1140 { 1141 struct perf_evsel *evsel, *leader; 1142 1143 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 1144 1145 /* instructions - sampling group leader */ 1146 evsel = leader = perf_evlist__first(evlist); 1147 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1148 TEST_ASSERT_VAL("wrong config", 1149 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); 1150 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1151 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1152 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1153 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 1154 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1155 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1156 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1157 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1158 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1159 1160 /* branch-misses - not sampling */ 1161 evsel = perf_evsel__next(evsel); 1162 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1163 TEST_ASSERT_VAL("wrong config", 1164 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config); 1165 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1166 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1167 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1168 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); 1169 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); 1170 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1171 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1172 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1173 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read); 1174 1175 return 0; 1176 } 1177 1178 static int test__checkevent_pinned_modifier(struct perf_evlist *evlist) 1179 { 1180 struct perf_evsel *evsel = perf_evlist__first(evlist); 1181 1182 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1183 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1184 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1185 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); 1186 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned); 1187 1188 return test__checkevent_symbolic_name(evlist); 1189 } 1190 1191 static int test__pinned_group(struct perf_evlist *evlist) 1192 { 1193 struct perf_evsel *evsel, *leader; 1194 1195 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries); 1196 1197 /* cycles - group leader */ 1198 evsel = leader = perf_evlist__first(evlist); 1199 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1200 TEST_ASSERT_VAL("wrong config", 1201 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); 1202 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); 1203 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader); 1204 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned); 1205 1206 /* cache-misses - can not be pinned, but will go on with the leader */ 1207 evsel = perf_evsel__next(evsel); 1208 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); 1209 TEST_ASSERT_VAL("wrong config", 1210 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config); 1211 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned); 1212 1213 /* branch-misses - ditto */ 1214 evsel = perf_evsel__next(evsel); 1215 TEST_ASSERT_VAL("wrong config", 1216 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config); 1217 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned); 1218 1219 return 0; 1220 } 1221 1222 static int test__checkevent_breakpoint_len(struct perf_evlist *evlist) 1223 { 1224 struct perf_evsel *evsel = perf_evlist__first(evlist); 1225 1226 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 1227 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); 1228 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 1229 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == 1230 evsel->attr.bp_type); 1231 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 == 1232 evsel->attr.bp_len); 1233 1234 return 0; 1235 } 1236 1237 static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist) 1238 { 1239 struct perf_evsel *evsel = perf_evlist__first(evlist); 1240 1241 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); 1242 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); 1243 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); 1244 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W == 1245 evsel->attr.bp_type); 1246 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 == 1247 evsel->attr.bp_len); 1248 1249 return 0; 1250 } 1251 1252 static int 1253 test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist) 1254 { 1255 struct perf_evsel *evsel = perf_evlist__first(evlist); 1256 1257 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); 1258 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); 1259 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); 1260 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); 1261 1262 return test__checkevent_breakpoint_rw(evlist); 1263 } 1264 1265 static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist) 1266 { 1267 struct perf_evsel *evsel = perf_evlist__first(evlist); 1268 1269 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries); 1270 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); 1271 TEST_ASSERT_VAL("wrong config", 1272 PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config); 1273 return 0; 1274 } 1275 1276 static int test__checkevent_config_symbol(struct perf_evlist *evlist) 1277 { 1278 struct perf_evsel *evsel = perf_evlist__first(evlist); 1279 1280 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0); 1281 return 0; 1282 } 1283 1284 static int test__checkevent_config_raw(struct perf_evlist *evlist) 1285 { 1286 struct perf_evsel *evsel = perf_evlist__first(evlist); 1287 1288 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0); 1289 return 0; 1290 } 1291 1292 static int test__checkevent_config_num(struct perf_evlist *evlist) 1293 { 1294 struct perf_evsel *evsel = perf_evlist__first(evlist); 1295 1296 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0); 1297 return 0; 1298 } 1299 1300 static int test__checkevent_config_cache(struct perf_evlist *evlist) 1301 { 1302 struct perf_evsel *evsel = perf_evlist__first(evlist); 1303 1304 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0); 1305 return 0; 1306 } 1307 1308 static int count_tracepoints(void) 1309 { 1310 struct dirent *events_ent; 1311 DIR *events_dir; 1312 int cnt = 0; 1313 1314 events_dir = opendir(tracing_events_path); 1315 1316 TEST_ASSERT_VAL("Can't open events dir", events_dir); 1317 1318 while ((events_ent = readdir(events_dir))) { 1319 char sys_path[PATH_MAX]; 1320 struct dirent *sys_ent; 1321 DIR *sys_dir; 1322 1323 if (!strcmp(events_ent->d_name, ".") 1324 || !strcmp(events_ent->d_name, "..") 1325 || !strcmp(events_ent->d_name, "enable") 1326 || !strcmp(events_ent->d_name, "header_event") 1327 || !strcmp(events_ent->d_name, "header_page")) 1328 continue; 1329 1330 scnprintf(sys_path, PATH_MAX, "%s/%s", 1331 tracing_events_path, events_ent->d_name); 1332 1333 sys_dir = opendir(sys_path); 1334 TEST_ASSERT_VAL("Can't open sys dir", sys_dir); 1335 1336 while ((sys_ent = readdir(sys_dir))) { 1337 if (!strcmp(sys_ent->d_name, ".") 1338 || !strcmp(sys_ent->d_name, "..") 1339 || !strcmp(sys_ent->d_name, "enable") 1340 || !strcmp(sys_ent->d_name, "filter")) 1341 continue; 1342 1343 cnt++; 1344 } 1345 1346 closedir(sys_dir); 1347 } 1348 1349 closedir(events_dir); 1350 return cnt; 1351 } 1352 1353 static int test__all_tracepoints(struct perf_evlist *evlist) 1354 { 1355 TEST_ASSERT_VAL("wrong events count", 1356 count_tracepoints() == evlist->nr_entries); 1357 1358 return test__checkevent_tracepoint_multi(evlist); 1359 } 1360 1361 struct evlist_test { 1362 const char *name; 1363 __u32 type; 1364 const int id; 1365 int (*check)(struct perf_evlist *evlist); 1366 }; 1367 1368 static struct evlist_test test__events[] = { 1369 { 1370 .name = "syscalls:sys_enter_openat", 1371 .check = test__checkevent_tracepoint, 1372 .id = 0, 1373 }, 1374 { 1375 .name = "syscalls:*", 1376 .check = test__checkevent_tracepoint_multi, 1377 .id = 1, 1378 }, 1379 { 1380 .name = "r1a", 1381 .check = test__checkevent_raw, 1382 .id = 2, 1383 }, 1384 { 1385 .name = "1:1", 1386 .check = test__checkevent_numeric, 1387 .id = 3, 1388 }, 1389 { 1390 .name = "instructions", 1391 .check = test__checkevent_symbolic_name, 1392 .id = 4, 1393 }, 1394 { 1395 .name = "cycles/period=100000,config2/", 1396 .check = test__checkevent_symbolic_name_config, 1397 .id = 5, 1398 }, 1399 { 1400 .name = "faults", 1401 .check = test__checkevent_symbolic_alias, 1402 .id = 6, 1403 }, 1404 { 1405 .name = "L1-dcache-load-miss", 1406 .check = test__checkevent_genhw, 1407 .id = 7, 1408 }, 1409 { 1410 .name = "mem:0", 1411 .check = test__checkevent_breakpoint, 1412 .id = 8, 1413 }, 1414 { 1415 .name = "mem:0:x", 1416 .check = test__checkevent_breakpoint_x, 1417 .id = 9, 1418 }, 1419 { 1420 .name = "mem:0:r", 1421 .check = test__checkevent_breakpoint_r, 1422 .id = 10, 1423 }, 1424 { 1425 .name = "mem:0:w", 1426 .check = test__checkevent_breakpoint_w, 1427 .id = 11, 1428 }, 1429 { 1430 .name = "syscalls:sys_enter_openat:k", 1431 .check = test__checkevent_tracepoint_modifier, 1432 .id = 12, 1433 }, 1434 { 1435 .name = "syscalls:*:u", 1436 .check = test__checkevent_tracepoint_multi_modifier, 1437 .id = 13, 1438 }, 1439 { 1440 .name = "r1a:kp", 1441 .check = test__checkevent_raw_modifier, 1442 .id = 14, 1443 }, 1444 { 1445 .name = "1:1:hp", 1446 .check = test__checkevent_numeric_modifier, 1447 .id = 15, 1448 }, 1449 { 1450 .name = "instructions:h", 1451 .check = test__checkevent_symbolic_name_modifier, 1452 .id = 16, 1453 }, 1454 { 1455 .name = "faults:u", 1456 .check = test__checkevent_symbolic_alias_modifier, 1457 .id = 17, 1458 }, 1459 { 1460 .name = "L1-dcache-load-miss:kp", 1461 .check = test__checkevent_genhw_modifier, 1462 .id = 18, 1463 }, 1464 { 1465 .name = "mem:0:u", 1466 .check = test__checkevent_breakpoint_modifier, 1467 .id = 19, 1468 }, 1469 { 1470 .name = "mem:0:x:k", 1471 .check = test__checkevent_breakpoint_x_modifier, 1472 .id = 20, 1473 }, 1474 { 1475 .name = "mem:0:r:hp", 1476 .check = test__checkevent_breakpoint_r_modifier, 1477 .id = 21, 1478 }, 1479 { 1480 .name = "mem:0:w:up", 1481 .check = test__checkevent_breakpoint_w_modifier, 1482 .id = 22, 1483 }, 1484 { 1485 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp", 1486 .check = test__checkevent_list, 1487 .id = 23, 1488 }, 1489 { 1490 .name = "instructions:G", 1491 .check = test__checkevent_exclude_host_modifier, 1492 .id = 24, 1493 }, 1494 { 1495 .name = "instructions:H", 1496 .check = test__checkevent_exclude_guest_modifier, 1497 .id = 25, 1498 }, 1499 { 1500 .name = "mem:0:rw", 1501 .check = test__checkevent_breakpoint_rw, 1502 .id = 26, 1503 }, 1504 { 1505 .name = "mem:0:rw:kp", 1506 .check = test__checkevent_breakpoint_rw_modifier, 1507 .id = 27, 1508 }, 1509 { 1510 .name = "{instructions:k,cycles:upp}", 1511 .check = test__group1, 1512 .id = 28, 1513 }, 1514 { 1515 .name = "{faults:k,cache-references}:u,cycles:k", 1516 .check = test__group2, 1517 .id = 29, 1518 }, 1519 { 1520 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u", 1521 .check = test__group3, 1522 .id = 30, 1523 }, 1524 { 1525 .name = "{cycles:u,instructions:kp}:p", 1526 .check = test__group4, 1527 .id = 31, 1528 }, 1529 { 1530 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles", 1531 .check = test__group5, 1532 .id = 32, 1533 }, 1534 { 1535 .name = "*:*", 1536 .check = test__all_tracepoints, 1537 .id = 33, 1538 }, 1539 { 1540 .name = "{cycles,cache-misses:G}:H", 1541 .check = test__group_gh1, 1542 .id = 34, 1543 }, 1544 { 1545 .name = "{cycles,cache-misses:H}:G", 1546 .check = test__group_gh2, 1547 .id = 35, 1548 }, 1549 { 1550 .name = "{cycles:G,cache-misses:H}:u", 1551 .check = test__group_gh3, 1552 .id = 36, 1553 }, 1554 { 1555 .name = "{cycles:G,cache-misses:H}:uG", 1556 .check = test__group_gh4, 1557 .id = 37, 1558 }, 1559 { 1560 .name = "{cycles,cache-misses,branch-misses}:S", 1561 .check = test__leader_sample1, 1562 .id = 38, 1563 }, 1564 { 1565 .name = "{instructions,branch-misses}:Su", 1566 .check = test__leader_sample2, 1567 .id = 39, 1568 }, 1569 { 1570 .name = "instructions:uDp", 1571 .check = test__checkevent_pinned_modifier, 1572 .id = 40, 1573 }, 1574 { 1575 .name = "{cycles,cache-misses,branch-misses}:D", 1576 .check = test__pinned_group, 1577 .id = 41, 1578 }, 1579 { 1580 .name = "mem:0/1", 1581 .check = test__checkevent_breakpoint_len, 1582 .id = 42, 1583 }, 1584 { 1585 .name = "mem:0/2:w", 1586 .check = test__checkevent_breakpoint_len_w, 1587 .id = 43, 1588 }, 1589 { 1590 .name = "mem:0/4:rw:u", 1591 .check = test__checkevent_breakpoint_len_rw_modifier, 1592 .id = 44 1593 }, 1594 #if defined(__s390x__) 1595 { 1596 .name = "kvm-s390:kvm_s390_create_vm", 1597 .check = test__checkevent_tracepoint, 1598 .id = 100, 1599 }, 1600 #endif 1601 { 1602 .name = "instructions:I", 1603 .check = test__checkevent_exclude_idle_modifier, 1604 .id = 45, 1605 }, 1606 { 1607 .name = "instructions:kIG", 1608 .check = test__checkevent_exclude_idle_modifier_1, 1609 .id = 46, 1610 }, 1611 { 1612 .name = "task-clock:P,cycles", 1613 .check = test__checkevent_precise_max_modifier, 1614 .id = 47, 1615 }, 1616 { 1617 .name = "instructions/name=insn/", 1618 .check = test__checkevent_config_symbol, 1619 .id = 48, 1620 }, 1621 { 1622 .name = "r1234/name=rawpmu/", 1623 .check = test__checkevent_config_raw, 1624 .id = 49, 1625 }, 1626 { 1627 .name = "4:0x6530160/name=numpmu/", 1628 .check = test__checkevent_config_num, 1629 .id = 50, 1630 }, 1631 { 1632 .name = "L1-dcache-misses/name=cachepmu/", 1633 .check = test__checkevent_config_cache, 1634 .id = 51, 1635 }, 1636 }; 1637 1638 static struct evlist_test test__events_pmu[] = { 1639 { 1640 .name = "cpu/config=10,config1,config2=3,period=1000/u", 1641 .check = test__checkevent_pmu, 1642 .id = 0, 1643 }, 1644 { 1645 .name = "cpu/config=1,name=krava/u,cpu/config=2/u", 1646 .check = test__checkevent_pmu_name, 1647 .id = 1, 1648 }, 1649 { 1650 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/", 1651 .check = test__checkevent_pmu_partial_time_callgraph, 1652 .id = 2, 1653 }, 1654 }; 1655 1656 struct terms_test { 1657 const char *str; 1658 __u32 type; 1659 int (*check)(struct list_head *terms); 1660 }; 1661 1662 static struct terms_test test__terms[] = { 1663 [0] = { 1664 .str = "config=10,config1,config2=3,umask=1", 1665 .check = test__checkterms_simple, 1666 }, 1667 }; 1668 1669 static int test_event(struct evlist_test *e) 1670 { 1671 struct perf_evlist *evlist; 1672 int ret; 1673 1674 evlist = perf_evlist__new(); 1675 if (evlist == NULL) 1676 return -ENOMEM; 1677 1678 ret = parse_events(evlist, e->name, NULL); 1679 if (ret) { 1680 pr_debug("failed to parse event '%s', err %d\n", 1681 e->name, ret); 1682 } else { 1683 ret = e->check(evlist); 1684 } 1685 1686 perf_evlist__delete(evlist); 1687 1688 return ret; 1689 } 1690 1691 static int test_events(struct evlist_test *events, unsigned cnt) 1692 { 1693 int ret1, ret2 = 0; 1694 unsigned i; 1695 1696 for (i = 0; i < cnt; i++) { 1697 struct evlist_test *e = &events[i]; 1698 1699 pr_debug("running test %d '%s'\n", e->id, e->name); 1700 ret1 = test_event(e); 1701 if (ret1) 1702 ret2 = ret1; 1703 } 1704 1705 return ret2; 1706 } 1707 1708 static int test_term(struct terms_test *t) 1709 { 1710 struct list_head terms; 1711 int ret; 1712 1713 INIT_LIST_HEAD(&terms); 1714 1715 ret = parse_events_terms(&terms, t->str); 1716 if (ret) { 1717 pr_debug("failed to parse terms '%s', err %d\n", 1718 t->str , ret); 1719 return ret; 1720 } 1721 1722 ret = t->check(&terms); 1723 parse_events_terms__purge(&terms); 1724 1725 return ret; 1726 } 1727 1728 static int test_terms(struct terms_test *terms, unsigned cnt) 1729 { 1730 int ret = 0; 1731 unsigned i; 1732 1733 for (i = 0; i < cnt; i++) { 1734 struct terms_test *t = &terms[i]; 1735 1736 pr_debug("running test %d '%s'\n", i, t->str); 1737 ret = test_term(t); 1738 if (ret) 1739 break; 1740 } 1741 1742 return ret; 1743 } 1744 1745 static int test_pmu(void) 1746 { 1747 struct stat st; 1748 char path[PATH_MAX]; 1749 int ret; 1750 1751 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/", 1752 sysfs__mountpoint()); 1753 1754 ret = stat(path, &st); 1755 if (ret) 1756 pr_debug("omitting PMU cpu tests\n"); 1757 return !ret; 1758 } 1759 1760 static int test_pmu_events(void) 1761 { 1762 struct stat st; 1763 char path[PATH_MAX]; 1764 struct dirent *ent; 1765 DIR *dir; 1766 int ret; 1767 1768 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/", 1769 sysfs__mountpoint()); 1770 1771 ret = stat(path, &st); 1772 if (ret) { 1773 pr_debug("omitting PMU cpu events tests\n"); 1774 return 0; 1775 } 1776 1777 dir = opendir(path); 1778 if (!dir) { 1779 pr_debug("can't open pmu event dir"); 1780 return -1; 1781 } 1782 1783 while (!ret && (ent = readdir(dir))) { 1784 struct evlist_test e; 1785 char name[2 * NAME_MAX + 1 + 12 + 3]; 1786 1787 /* Names containing . are special and cannot be used directly */ 1788 if (strchr(ent->d_name, '.')) 1789 continue; 1790 1791 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name); 1792 1793 e.name = name; 1794 e.check = test__checkevent_pmu_events; 1795 1796 ret = test_event(&e); 1797 if (ret) 1798 break; 1799 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name); 1800 e.name = name; 1801 e.check = test__checkevent_pmu_events_mix; 1802 ret = test_event(&e); 1803 } 1804 1805 closedir(dir); 1806 return ret; 1807 } 1808 1809 static void debug_warn(const char *warn, va_list params) 1810 { 1811 char msg[1024]; 1812 1813 if (verbose <= 0) 1814 return; 1815 1816 vsnprintf(msg, sizeof(msg), warn, params); 1817 fprintf(stderr, " Warning: %s\n", msg); 1818 } 1819 1820 int test__parse_events(int subtest __maybe_unused) 1821 { 1822 int ret1, ret2 = 0; 1823 1824 #define TEST_EVENTS(tests) \ 1825 do { \ 1826 ret1 = test_events(tests, ARRAY_SIZE(tests)); \ 1827 if (!ret2) \ 1828 ret2 = ret1; \ 1829 } while (0) 1830 1831 set_warning_routine(debug_warn); 1832 1833 TEST_EVENTS(test__events); 1834 1835 if (test_pmu()) 1836 TEST_EVENTS(test__events_pmu); 1837 1838 if (test_pmu()) { 1839 int ret = test_pmu_events(); 1840 if (ret) 1841 return ret; 1842 } 1843 1844 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms)); 1845 if (!ret2) 1846 ret2 = ret1; 1847 1848 return ret2; 1849 } 1850