0001
0002 #include "parse-events.h"
0003 #include "evsel.h"
0004 #include "evlist.h"
0005 #include <api/fs/fs.h>
0006 #include "tests.h"
0007 #include "debug.h"
0008 #include "pmu.h"
0009 #include "pmu-hybrid.h"
0010 #include <dirent.h>
0011 #include <errno.h>
0012 #include "fncache.h"
0013 #include <sys/types.h>
0014 #include <sys/stat.h>
0015 #include <unistd.h>
0016 #include <linux/kernel.h>
0017 #include <linux/hw_breakpoint.h>
0018 #include <api/fs/tracing_path.h>
0019
0020 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
0021 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
0022
0023 #if defined(__s390x__)
0024
0025
0026
0027
0028 static bool kvm_s390_create_vm_valid(void)
0029 {
0030 char *eventfile;
0031 bool rc = false;
0032
0033 eventfile = get_events_file("kvm-s390");
0034
0035 if (eventfile) {
0036 DIR *mydir = opendir(eventfile);
0037
0038 if (mydir) {
0039 rc = true;
0040 closedir(mydir);
0041 }
0042 put_events_file(eventfile);
0043 }
0044
0045 return rc;
0046 }
0047 #endif
0048
0049 static int test__checkevent_tracepoint(struct evlist *evlist)
0050 {
0051 struct evsel *evsel = evlist__first(evlist);
0052
0053 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0054 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->core.nr_groups);
0055 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
0056 TEST_ASSERT_VAL("wrong sample_type",
0057 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
0058 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
0059 return TEST_OK;
0060 }
0061
0062 static int test__checkevent_tracepoint_multi(struct evlist *evlist)
0063 {
0064 struct evsel *evsel;
0065
0066 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
0067 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->core.nr_groups);
0068
0069 evlist__for_each_entry(evlist, evsel) {
0070 TEST_ASSERT_VAL("wrong type",
0071 PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
0072 TEST_ASSERT_VAL("wrong sample_type",
0073 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
0074 TEST_ASSERT_VAL("wrong sample_period",
0075 1 == evsel->core.attr.sample_period);
0076 }
0077 return TEST_OK;
0078 }
0079
0080 static int test__checkevent_raw(struct evlist *evlist)
0081 {
0082 struct evsel *evsel = evlist__first(evlist);
0083
0084 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0085 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0086 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
0087 return TEST_OK;
0088 }
0089
0090 static int test__checkevent_numeric(struct evlist *evlist)
0091 {
0092 struct evsel *evsel = evlist__first(evlist);
0093
0094 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0095 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
0096 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
0097 return TEST_OK;
0098 }
0099
0100 static int test__checkevent_symbolic_name(struct evlist *evlist)
0101 {
0102 struct evsel *evsel = evlist__first(evlist);
0103
0104 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0105 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0106 TEST_ASSERT_VAL("wrong config",
0107 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
0108 return TEST_OK;
0109 }
0110
0111 static int test__checkevent_symbolic_name_config(struct evlist *evlist)
0112 {
0113 struct evsel *evsel = evlist__first(evlist);
0114
0115 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0116 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0117 TEST_ASSERT_VAL("wrong config",
0118 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0119
0120
0121
0122
0123 TEST_ASSERT_VAL("wrong period",
0124 0 == evsel->core.attr.sample_period);
0125 TEST_ASSERT_VAL("wrong config1",
0126 0 == evsel->core.attr.config1);
0127 TEST_ASSERT_VAL("wrong config2",
0128 1 == evsel->core.attr.config2);
0129 return TEST_OK;
0130 }
0131
0132 static int test__checkevent_symbolic_alias(struct evlist *evlist)
0133 {
0134 struct evsel *evsel = evlist__first(evlist);
0135
0136 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0137 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
0138 TEST_ASSERT_VAL("wrong config",
0139 PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
0140 return TEST_OK;
0141 }
0142
0143 static int test__checkevent_genhw(struct evlist *evlist)
0144 {
0145 struct evsel *evsel = evlist__first(evlist);
0146
0147 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0148 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
0149 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->core.attr.config);
0150 return TEST_OK;
0151 }
0152
0153 static int test__checkevent_breakpoint(struct evlist *evlist)
0154 {
0155 struct evsel *evsel = evlist__first(evlist);
0156
0157 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0158 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
0159 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
0160 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
0161 evsel->core.attr.bp_type);
0162 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
0163 evsel->core.attr.bp_len);
0164 return TEST_OK;
0165 }
0166
0167 static int test__checkevent_breakpoint_x(struct evlist *evlist)
0168 {
0169 struct evsel *evsel = evlist__first(evlist);
0170
0171 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0172 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
0173 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
0174 TEST_ASSERT_VAL("wrong bp_type",
0175 HW_BREAKPOINT_X == evsel->core.attr.bp_type);
0176 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
0177 return TEST_OK;
0178 }
0179
0180 static int test__checkevent_breakpoint_r(struct evlist *evlist)
0181 {
0182 struct evsel *evsel = evlist__first(evlist);
0183
0184 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0185 TEST_ASSERT_VAL("wrong type",
0186 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
0187 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
0188 TEST_ASSERT_VAL("wrong bp_type",
0189 HW_BREAKPOINT_R == evsel->core.attr.bp_type);
0190 TEST_ASSERT_VAL("wrong bp_len",
0191 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
0192 return TEST_OK;
0193 }
0194
0195 static int test__checkevent_breakpoint_w(struct evlist *evlist)
0196 {
0197 struct evsel *evsel = evlist__first(evlist);
0198
0199 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0200 TEST_ASSERT_VAL("wrong type",
0201 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
0202 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
0203 TEST_ASSERT_VAL("wrong bp_type",
0204 HW_BREAKPOINT_W == evsel->core.attr.bp_type);
0205 TEST_ASSERT_VAL("wrong bp_len",
0206 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
0207 return TEST_OK;
0208 }
0209
0210 static int test__checkevent_breakpoint_rw(struct evlist *evlist)
0211 {
0212 struct evsel *evsel = evlist__first(evlist);
0213
0214 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0215 TEST_ASSERT_VAL("wrong type",
0216 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
0217 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
0218 TEST_ASSERT_VAL("wrong bp_type",
0219 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
0220 TEST_ASSERT_VAL("wrong bp_len",
0221 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
0222 return TEST_OK;
0223 }
0224
0225 static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
0226 {
0227 struct evsel *evsel = evlist__first(evlist);
0228
0229 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0230 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0231 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0232 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0233
0234 return test__checkevent_tracepoint(evlist);
0235 }
0236
0237 static int
0238 test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
0239 {
0240 struct evsel *evsel;
0241
0242 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
0243
0244 evlist__for_each_entry(evlist, evsel) {
0245 TEST_ASSERT_VAL("wrong exclude_user",
0246 !evsel->core.attr.exclude_user);
0247 TEST_ASSERT_VAL("wrong exclude_kernel",
0248 evsel->core.attr.exclude_kernel);
0249 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0250 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0251 }
0252
0253 return test__checkevent_tracepoint_multi(evlist);
0254 }
0255
0256 static int test__checkevent_raw_modifier(struct evlist *evlist)
0257 {
0258 struct evsel *evsel = evlist__first(evlist);
0259
0260 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0261 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0262 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0263 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0264
0265 return test__checkevent_raw(evlist);
0266 }
0267
0268 static int test__checkevent_numeric_modifier(struct evlist *evlist)
0269 {
0270 struct evsel *evsel = evlist__first(evlist);
0271
0272 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0273 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0274 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0275 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0276
0277 return test__checkevent_numeric(evlist);
0278 }
0279
0280 static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
0281 {
0282 struct evsel *evsel = evlist__first(evlist);
0283
0284 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0285 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0286 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0287 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0288
0289 return test__checkevent_symbolic_name(evlist);
0290 }
0291
0292 static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
0293 {
0294 struct evsel *evsel = evlist__first(evlist);
0295
0296 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0297 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0298
0299 return test__checkevent_symbolic_name(evlist);
0300 }
0301
0302 static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
0303 {
0304 struct evsel *evsel = evlist__first(evlist);
0305
0306 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0307 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0308
0309 return test__checkevent_symbolic_name(evlist);
0310 }
0311
0312 static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
0313 {
0314 struct evsel *evsel = evlist__first(evlist);
0315
0316 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0317 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0318 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0319 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0320
0321 return test__checkevent_symbolic_alias(evlist);
0322 }
0323
0324 static int test__checkevent_genhw_modifier(struct evlist *evlist)
0325 {
0326 struct evsel *evsel = evlist__first(evlist);
0327
0328 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0329 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0330 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0331 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0332
0333 return test__checkevent_genhw(evlist);
0334 }
0335
0336 static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
0337 {
0338 struct evsel *evsel = evlist__first(evlist);
0339
0340 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
0341 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0342 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0343 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0344 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0345 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0346 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0347
0348 return test__checkevent_symbolic_name(evlist);
0349 }
0350
0351 static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
0352 {
0353 struct evsel *evsel = evlist__first(evlist);
0354
0355 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
0356 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0357 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0358 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0359 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0360 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0361 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0362
0363 return test__checkevent_symbolic_name(evlist);
0364 }
0365
0366 static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
0367 {
0368 struct evsel *evsel = evlist__first(evlist);
0369
0370
0371 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0372 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0373 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0374 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0375 TEST_ASSERT_VAL("wrong name",
0376 !strcmp(evsel__name(evsel), "mem:0:u"));
0377
0378 return test__checkevent_breakpoint(evlist);
0379 }
0380
0381 static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
0382 {
0383 struct evsel *evsel = evlist__first(evlist);
0384
0385 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0386 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0387 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0388 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0389 TEST_ASSERT_VAL("wrong name",
0390 !strcmp(evsel__name(evsel), "mem:0:x:k"));
0391
0392 return test__checkevent_breakpoint_x(evlist);
0393 }
0394
0395 static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
0396 {
0397 struct evsel *evsel = evlist__first(evlist);
0398
0399 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0400 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0401 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0402 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0403 TEST_ASSERT_VAL("wrong name",
0404 !strcmp(evsel__name(evsel), "mem:0:r:hp"));
0405
0406 return test__checkevent_breakpoint_r(evlist);
0407 }
0408
0409 static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
0410 {
0411 struct evsel *evsel = evlist__first(evlist);
0412
0413 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0414 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0415 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0416 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0417 TEST_ASSERT_VAL("wrong name",
0418 !strcmp(evsel__name(evsel), "mem:0:w:up"));
0419
0420 return test__checkevent_breakpoint_w(evlist);
0421 }
0422
0423 static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
0424 {
0425 struct evsel *evsel = evlist__first(evlist);
0426
0427 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0428 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0429 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0430 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0431 TEST_ASSERT_VAL("wrong name",
0432 !strcmp(evsel__name(evsel), "mem:0:rw:kp"));
0433
0434 return test__checkevent_breakpoint_rw(evlist);
0435 }
0436
0437 static int test__checkevent_pmu(struct evlist *evlist)
0438 {
0439
0440 struct evsel *evsel = evlist__first(evlist);
0441
0442 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0443 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0444 TEST_ASSERT_VAL("wrong config", 10 == evsel->core.attr.config);
0445 TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1);
0446 TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2);
0447
0448
0449
0450
0451 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
0452
0453 return TEST_OK;
0454 }
0455
0456 static int test__checkevent_list(struct evlist *evlist)
0457 {
0458 struct evsel *evsel = evlist__first(evlist);
0459
0460 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
0461
0462
0463 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0464 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
0465 TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);
0466 TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
0467 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0468 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0469 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0470 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0471
0472
0473 evsel = evsel__next(evsel);
0474 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
0475 TEST_ASSERT_VAL("wrong sample_type",
0476 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
0477 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
0478 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0479 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0480 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0481 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0482
0483
0484 evsel = evsel__next(evsel);
0485 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
0486 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
0487 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0488 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0489 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0490 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
0491
0492 return TEST_OK;
0493 }
0494
0495 static int test__checkevent_pmu_name(struct evlist *evlist)
0496 {
0497 struct evsel *evsel = evlist__first(evlist);
0498
0499
0500 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0501 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0502 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
0503 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava"));
0504
0505
0506 evsel = evsel__next(evsel);
0507 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0508 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0509 TEST_ASSERT_VAL("wrong config", 2 == evsel->core.attr.config);
0510 TEST_ASSERT_VAL("wrong name",
0511 !strcmp(evsel__name(evsel), "cpu/config=2/u"));
0512
0513 return TEST_OK;
0514 }
0515
0516 static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
0517 {
0518 struct evsel *evsel = evlist__first(evlist);
0519
0520
0521 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0522 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0523 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
0524
0525
0526
0527
0528 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
0529 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
0530 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
0531
0532
0533 evsel = evsel__next(evsel);
0534 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0535 TEST_ASSERT_VAL("wrong config", 2 == evsel->core.attr.config);
0536
0537
0538
0539
0540 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
0541 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
0542 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
0543
0544 return TEST_OK;
0545 }
0546
0547 static int test__checkevent_pmu_events(struct evlist *evlist)
0548 {
0549 struct evsel *evsel = evlist__first(evlist);
0550
0551 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
0552 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0553 TEST_ASSERT_VAL("wrong exclude_user",
0554 !evsel->core.attr.exclude_user);
0555 TEST_ASSERT_VAL("wrong exclude_kernel",
0556 evsel->core.attr.exclude_kernel);
0557 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0558 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0559 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
0560 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
0561
0562 return TEST_OK;
0563 }
0564
0565
0566 static int test__checkevent_pmu_events_mix(struct evlist *evlist)
0567 {
0568 struct evsel *evsel = evlist__first(evlist);
0569
0570
0571 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0572 TEST_ASSERT_VAL("wrong exclude_user",
0573 !evsel->core.attr.exclude_user);
0574 TEST_ASSERT_VAL("wrong exclude_kernel",
0575 evsel->core.attr.exclude_kernel);
0576 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0577 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0578 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
0579 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
0580
0581
0582 evsel = evsel__next(evsel);
0583 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0584 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
0585 TEST_ASSERT_VAL("wrong exclude_user",
0586 !evsel->core.attr.exclude_user);
0587 TEST_ASSERT_VAL("wrong exclude_kernel",
0588 evsel->core.attr.exclude_kernel);
0589 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0590 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0591 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
0592 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned);
0593
0594 return TEST_OK;
0595 }
0596
0597 static int test__checkterms_simple(struct list_head *terms)
0598 {
0599 struct parse_events_term *term;
0600
0601
0602 term = list_entry(terms->next, struct parse_events_term, list);
0603 TEST_ASSERT_VAL("wrong type term",
0604 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
0605 TEST_ASSERT_VAL("wrong type val",
0606 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
0607 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
0608 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));
0609
0610
0611 term = list_entry(term->list.next, struct parse_events_term, list);
0612 TEST_ASSERT_VAL("wrong type term",
0613 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
0614 TEST_ASSERT_VAL("wrong type val",
0615 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
0616 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
0617 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1"));
0618
0619
0620 term = list_entry(term->list.next, struct parse_events_term, list);
0621 TEST_ASSERT_VAL("wrong type term",
0622 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
0623 TEST_ASSERT_VAL("wrong type val",
0624 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
0625 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
0626 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2"));
0627
0628
0629 term = list_entry(term->list.next, struct parse_events_term, list);
0630 TEST_ASSERT_VAL("wrong type term",
0631 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
0632 TEST_ASSERT_VAL("wrong type val",
0633 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
0634 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
0635 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
0636
0637
0638
0639
0640
0641
0642
0643
0644 term = list_entry(term->list.next, struct parse_events_term, list);
0645 TEST_ASSERT_VAL("wrong type term",
0646 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
0647 TEST_ASSERT_VAL("wrong type val",
0648 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
0649 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
0650 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "read"));
0651
0652
0653
0654
0655
0656
0657
0658 term = list_entry(term->list.next, struct parse_events_term, list);
0659 TEST_ASSERT_VAL("wrong type term",
0660 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
0661 TEST_ASSERT_VAL("wrong type val",
0662 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
0663 TEST_ASSERT_VAL("wrong val", term->val.num == 0xead);
0664 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));
0665 return TEST_OK;
0666 }
0667
0668 static int test__group1(struct evlist *evlist)
0669 {
0670 struct evsel *evsel, *leader;
0671
0672 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0673 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
0674
0675
0676 evsel = leader = evlist__first(evlist);
0677 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0678 TEST_ASSERT_VAL("wrong config",
0679 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
0680 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0681 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0682 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0683 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0684 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0685 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0686 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0687 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0688 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0689 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0690
0691
0692 evsel = evsel__next(evsel);
0693 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0694 TEST_ASSERT_VAL("wrong config",
0695 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0696 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0697 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0698 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0699
0700 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0701 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0702 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
0703 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0704 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0705 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0706
0707 return TEST_OK;
0708 }
0709
0710 static int test__group2(struct evlist *evlist)
0711 {
0712 struct evsel *evsel, *leader;
0713
0714 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
0715 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
0716
0717
0718 evsel = leader = evlist__first(evlist);
0719 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
0720 TEST_ASSERT_VAL("wrong config",
0721 PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
0722 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0723 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0724 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0725 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0726 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0727 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0728 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0729 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0730 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0731 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0732
0733
0734 evsel = evsel__next(evsel);
0735 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0736 TEST_ASSERT_VAL("wrong config",
0737 PERF_COUNT_HW_CACHE_REFERENCES == evsel->core.attr.config);
0738 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0739 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0740 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0741 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0742 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0743 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0744 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0745 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0746 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0747
0748
0749 evsel = evsel__next(evsel);
0750 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0751 TEST_ASSERT_VAL("wrong config",
0752 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0753 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0754 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0755 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0756 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0757 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0758 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0759 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0760 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0761
0762 return TEST_OK;
0763 }
0764
0765 static int test__group3(struct evlist *evlist __maybe_unused)
0766 {
0767 struct evsel *evsel, *leader;
0768
0769 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
0770 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->core.nr_groups);
0771
0772
0773 evsel = leader = evlist__first(evlist);
0774 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
0775 TEST_ASSERT_VAL("wrong sample_type",
0776 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
0777 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
0778 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0779 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0780 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0781 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0782 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0783 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0784 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0785 TEST_ASSERT_VAL("wrong group name",
0786 !strcmp(leader->group_name, "group1"));
0787 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0788 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0789 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0790
0791
0792 evsel = evsel__next(evsel);
0793 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0794 TEST_ASSERT_VAL("wrong config",
0795 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0796 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0797 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0798 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0799
0800 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0801 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0802 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 3);
0803 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0804 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
0805 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0806 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0807
0808
0809 evsel = leader = evsel__next(evsel);
0810 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0811 TEST_ASSERT_VAL("wrong config",
0812 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0813 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0814 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0815 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0816 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0817 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0818 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0819 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0820 TEST_ASSERT_VAL("wrong group name",
0821 !strcmp(leader->group_name, "group2"));
0822 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0823 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0824 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0825
0826
0827 evsel = evsel__next(evsel);
0828 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
0829 TEST_ASSERT_VAL("wrong config", 3 == evsel->core.attr.config);
0830 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0831 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0832 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0833 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0834 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0835 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0836 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0837 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0838 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0839
0840
0841 evsel = evsel__next(evsel);
0842 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0843 TEST_ASSERT_VAL("wrong config",
0844 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
0845 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0846 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0847 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0848 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0849 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0850 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0851 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0852 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0853
0854 return TEST_OK;
0855 }
0856
0857 static int test__group4(struct evlist *evlist __maybe_unused)
0858 {
0859 struct evsel *evsel, *leader;
0860
0861 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0862 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
0863
0864
0865 evsel = leader = evlist__first(evlist);
0866 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0867 TEST_ASSERT_VAL("wrong config",
0868 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0869 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0870 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
0871 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0872
0873 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0874 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0875 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);
0876 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
0877 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0878 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0879 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0880 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0881
0882
0883 evsel = evsel__next(evsel);
0884 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0885 TEST_ASSERT_VAL("wrong config",
0886 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
0887 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
0888 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0889 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
0890
0891 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0892 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0893 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
0894 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0895 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0896 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0897
0898 return TEST_OK;
0899 }
0900
0901 static int test__group5(struct evlist *evlist __maybe_unused)
0902 {
0903 struct evsel *evsel, *leader;
0904
0905 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
0906 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->core.nr_groups);
0907
0908
0909 evsel = leader = evlist__first(evlist);
0910 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0911 TEST_ASSERT_VAL("wrong config",
0912 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0913 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0914 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0915 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0916 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0917 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0918 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0919 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
0920 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0921 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0922 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0923 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0924
0925
0926 evsel = evsel__next(evsel);
0927 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0928 TEST_ASSERT_VAL("wrong config",
0929 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
0930 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0931 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0932 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0933 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0934 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0935 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0936 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0937 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0938 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0939
0940
0941 evsel = leader = evsel__next(evsel);
0942 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0943 TEST_ASSERT_VAL("wrong config",
0944 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0945 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0946 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0947 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0948 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0949 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0950 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0951 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
0952 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0953 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
0954 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
0955 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
0956
0957
0958 evsel = evsel__next(evsel);
0959 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0960 TEST_ASSERT_VAL("wrong config",
0961 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
0962 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0963 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0964 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0965 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
0966 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
0967 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0968 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
0969 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
0970
0971
0972 evsel = evsel__next(evsel);
0973 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0974 TEST_ASSERT_VAL("wrong config",
0975 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0976 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
0977 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
0978 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
0979 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
0980 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
0981 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
0982 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
0983
0984 return TEST_OK;
0985 }
0986
0987 static int test__group_gh1(struct evlist *evlist)
0988 {
0989 struct evsel *evsel, *leader;
0990
0991 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
0992 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
0993
0994
0995 evsel = leader = evlist__first(evlist);
0996 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
0997 TEST_ASSERT_VAL("wrong config",
0998 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
0999 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
1010
1011 evsel = evsel__next(evsel);
1012 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1013 TEST_ASSERT_VAL("wrong config",
1014 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
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 return TEST_OK;
1025 }
1026
1027 static int test__group_gh2(struct evlist *evlist)
1028 {
1029 struct evsel *evsel, *leader;
1030
1031 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1032 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
1033
1034
1035 evsel = leader = evlist__first(evlist);
1036 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1037 TEST_ASSERT_VAL("wrong config",
1038 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1039 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1040 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1041 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1042 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1043 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1044 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1045 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1046 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1047 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1048 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1049
1050
1051 evsel = evsel__next(evsel);
1052 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1053 TEST_ASSERT_VAL("wrong config",
1054 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1055 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1056 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1057 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1058 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1059 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1060 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1061 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1062 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1063
1064 return TEST_OK;
1065 }
1066
1067 static int test__group_gh3(struct evlist *evlist)
1068 {
1069 struct evsel *evsel, *leader;
1070
1071 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1072 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
1073
1074
1075 evsel = leader = evlist__first(evlist);
1076 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1077 TEST_ASSERT_VAL("wrong config",
1078 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1079 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1080 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1081 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1082 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1083 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1084 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1085 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1086 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1087 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1088 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1089
1090
1091 evsel = evsel__next(evsel);
1092 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1093 TEST_ASSERT_VAL("wrong config",
1094 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1095 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1096 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1097 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1098 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1099 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1100 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1101 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1102 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1103
1104 return TEST_OK;
1105 }
1106
1107 static int test__group_gh4(struct evlist *evlist)
1108 {
1109 struct evsel *evsel, *leader;
1110
1111 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1112 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->core.nr_groups);
1113
1114
1115 evsel = leader = evlist__first(evlist);
1116 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1117 TEST_ASSERT_VAL("wrong config",
1118 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1119 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1120 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1121 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1122 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1123 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1124 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1125 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1126 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1127 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1128 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1129
1130
1131 evsel = evsel__next(evsel);
1132 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1133 TEST_ASSERT_VAL("wrong config",
1134 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1135 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1136 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1137 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1138 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1139 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1140 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1141 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1142 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1143
1144 return TEST_OK;
1145 }
1146
1147 static int test__leader_sample1(struct evlist *evlist)
1148 {
1149 struct evsel *evsel, *leader;
1150
1151 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1152
1153
1154 evsel = leader = evlist__first(evlist);
1155 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1156 TEST_ASSERT_VAL("wrong config",
1157 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1158 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1159 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1160 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1161 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1162 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1163 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1164 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1165 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1166 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1167
1168
1169 evsel = evsel__next(evsel);
1170 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1171 TEST_ASSERT_VAL("wrong config",
1172 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1173 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1174 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1175 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1176 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1177 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1178 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1179 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1180 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1181
1182
1183 evsel = evsel__next(evsel);
1184 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1185 TEST_ASSERT_VAL("wrong config",
1186 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1187 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1188 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1189 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1190 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1191 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1192 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1193 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1194 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1195 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1196
1197 return TEST_OK;
1198 }
1199
1200 static int test__leader_sample2(struct evlist *evlist __maybe_unused)
1201 {
1202 struct evsel *evsel, *leader;
1203
1204 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1205
1206
1207 evsel = leader = evlist__first(evlist);
1208 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1209 TEST_ASSERT_VAL("wrong config",
1210 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
1211 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1212 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1213 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1214 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1215 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1216 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1217 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1218 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1219 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1220
1221
1222 evsel = evsel__next(evsel);
1223 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1224 TEST_ASSERT_VAL("wrong config",
1225 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1226 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1227 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1228 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1229 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1230 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1231 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1232 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1233 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1234 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1235
1236 return TEST_OK;
1237 }
1238
1239 static int test__checkevent_pinned_modifier(struct evlist *evlist)
1240 {
1241 struct evsel *evsel = evlist__first(evlist);
1242
1243 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1244 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1245 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1246 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1247 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1248
1249 return test__checkevent_symbolic_name(evlist);
1250 }
1251
1252 static int test__pinned_group(struct evlist *evlist)
1253 {
1254 struct evsel *evsel, *leader;
1255
1256 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1257
1258
1259 evsel = leader = evlist__first(evlist);
1260 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1261 TEST_ASSERT_VAL("wrong config",
1262 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1263 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1264 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1265 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1266
1267
1268 evsel = evsel__next(evsel);
1269 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1270 TEST_ASSERT_VAL("wrong config",
1271 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1272 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1273
1274
1275 evsel = evsel__next(evsel);
1276 TEST_ASSERT_VAL("wrong config",
1277 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1278 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1279
1280 return TEST_OK;
1281 }
1282
1283 static int test__checkevent_exclusive_modifier(struct evlist *evlist)
1284 {
1285 struct evsel *evsel = evlist__first(evlist);
1286
1287 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1288 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1289 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1290 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1291 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1292
1293 return test__checkevent_symbolic_name(evlist);
1294 }
1295
1296 static int test__exclusive_group(struct evlist *evlist)
1297 {
1298 struct evsel *evsel, *leader;
1299
1300 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1301
1302
1303 evsel = leader = evlist__first(evlist);
1304 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1305 TEST_ASSERT_VAL("wrong config",
1306 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1307 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1308 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1309 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1310
1311
1312 evsel = evsel__next(evsel);
1313 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1314 TEST_ASSERT_VAL("wrong config",
1315 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1316 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1317
1318
1319 evsel = evsel__next(evsel);
1320 TEST_ASSERT_VAL("wrong config",
1321 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1322 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1323
1324 return TEST_OK;
1325 }
1326 static int test__checkevent_breakpoint_len(struct evlist *evlist)
1327 {
1328 struct evsel *evsel = evlist__first(evlist);
1329
1330 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1331 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1332 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
1333 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1334 evsel->core.attr.bp_type);
1335 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1336 evsel->core.attr.bp_len);
1337
1338 return TEST_OK;
1339 }
1340
1341 static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
1342 {
1343 struct evsel *evsel = evlist__first(evlist);
1344
1345 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1346 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1347 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
1348 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1349 evsel->core.attr.bp_type);
1350 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1351 evsel->core.attr.bp_len);
1352
1353 return TEST_OK;
1354 }
1355
1356 static int
1357 test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
1358 {
1359 struct evsel *evsel = evlist__first(evlist);
1360
1361 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1362 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1363 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1364 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1365
1366 return test__checkevent_breakpoint_rw(evlist);
1367 }
1368
1369 static int test__checkevent_precise_max_modifier(struct evlist *evlist)
1370 {
1371 struct evsel *evsel = evlist__first(evlist);
1372
1373 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1374 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1375 TEST_ASSERT_VAL("wrong config",
1376 PERF_COUNT_SW_TASK_CLOCK == evsel->core.attr.config);
1377 return TEST_OK;
1378 }
1379
1380 static int test__checkevent_config_symbol(struct evlist *evlist)
1381 {
1382 struct evsel *evsel = evlist__first(evlist);
1383
1384 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1385 return TEST_OK;
1386 }
1387
1388 static int test__checkevent_config_raw(struct evlist *evlist)
1389 {
1390 struct evsel *evsel = evlist__first(evlist);
1391
1392 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1393 return TEST_OK;
1394 }
1395
1396 static int test__checkevent_config_num(struct evlist *evlist)
1397 {
1398 struct evsel *evsel = evlist__first(evlist);
1399
1400 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1401 return TEST_OK;
1402 }
1403
1404 static int test__checkevent_config_cache(struct evlist *evlist)
1405 {
1406 struct evsel *evsel = evlist__first(evlist);
1407
1408 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1409 return TEST_OK;
1410 }
1411
1412 static bool test__intel_pt_valid(void)
1413 {
1414 return !!perf_pmu__find("intel_pt");
1415 }
1416
1417 static int test__intel_pt(struct evlist *evlist)
1418 {
1419 struct evsel *evsel = evlist__first(evlist);
1420
1421 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0);
1422 return TEST_OK;
1423 }
1424
1425 static int test__checkevent_complex_name(struct evlist *evlist)
1426 {
1427 struct evsel *evsel = evlist__first(evlist);
1428
1429 TEST_ASSERT_VAL("wrong complex name parsing", strcmp(evsel->name, "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks") == 0);
1430 return TEST_OK;
1431 }
1432
1433 static int test__checkevent_raw_pmu(struct evlist *evlist)
1434 {
1435 struct evsel *evsel = evlist__first(evlist);
1436
1437 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1438 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1439 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1440 return TEST_OK;
1441 }
1442
1443 static int test__sym_event_slash(struct evlist *evlist)
1444 {
1445 struct evsel *evsel = evlist__first(evlist);
1446
1447 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1448 TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
1449 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1450 return TEST_OK;
1451 }
1452
1453 static int test__sym_event_dc(struct evlist *evlist)
1454 {
1455 struct evsel *evsel = evlist__first(evlist);
1456
1457 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1458 TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
1459 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1460 return TEST_OK;
1461 }
1462
1463 static int count_tracepoints(void)
1464 {
1465 struct dirent *events_ent;
1466 DIR *events_dir;
1467 int cnt = 0;
1468
1469 events_dir = tracing_events__opendir();
1470
1471 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1472
1473 while ((events_ent = readdir(events_dir))) {
1474 char *sys_path;
1475 struct dirent *sys_ent;
1476 DIR *sys_dir;
1477
1478 if (!strcmp(events_ent->d_name, ".")
1479 || !strcmp(events_ent->d_name, "..")
1480 || !strcmp(events_ent->d_name, "enable")
1481 || !strcmp(events_ent->d_name, "header_event")
1482 || !strcmp(events_ent->d_name, "header_page"))
1483 continue;
1484
1485 sys_path = get_events_file(events_ent->d_name);
1486 TEST_ASSERT_VAL("Can't get sys path", sys_path);
1487
1488 sys_dir = opendir(sys_path);
1489 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1490
1491 while ((sys_ent = readdir(sys_dir))) {
1492 if (!strcmp(sys_ent->d_name, ".")
1493 || !strcmp(sys_ent->d_name, "..")
1494 || !strcmp(sys_ent->d_name, "enable")
1495 || !strcmp(sys_ent->d_name, "filter"))
1496 continue;
1497
1498 cnt++;
1499 }
1500
1501 closedir(sys_dir);
1502 put_events_file(sys_path);
1503 }
1504
1505 closedir(events_dir);
1506 return cnt;
1507 }
1508
1509 static int test__all_tracepoints(struct evlist *evlist)
1510 {
1511 TEST_ASSERT_VAL("wrong events count",
1512 count_tracepoints() == evlist->core.nr_entries);
1513
1514 return test__checkevent_tracepoint_multi(evlist);
1515 }
1516
1517 static int test__hybrid_hw_event_with_pmu(struct evlist *evlist)
1518 {
1519 struct evsel *evsel = evlist__first(evlist);
1520
1521 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1522 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1523 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1524 return TEST_OK;
1525 }
1526
1527 static int test__hybrid_hw_group_event(struct evlist *evlist)
1528 {
1529 struct evsel *evsel, *leader;
1530
1531 evsel = leader = evlist__first(evlist);
1532 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1533 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1534 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1535 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1536
1537 evsel = evsel__next(evsel);
1538 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1539 TEST_ASSERT_VAL("wrong config", 0xc0 == evsel->core.attr.config);
1540 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1541 return TEST_OK;
1542 }
1543
1544 static int test__hybrid_sw_hw_group_event(struct evlist *evlist)
1545 {
1546 struct evsel *evsel, *leader;
1547
1548 evsel = leader = evlist__first(evlist);
1549 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1550 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1551 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1552
1553 evsel = evsel__next(evsel);
1554 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1555 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1556 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1557 return TEST_OK;
1558 }
1559
1560 static int test__hybrid_hw_sw_group_event(struct evlist *evlist)
1561 {
1562 struct evsel *evsel, *leader;
1563
1564 evsel = leader = evlist__first(evlist);
1565 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1566 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1567 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1568 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1569
1570 evsel = evsel__next(evsel);
1571 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1572 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1573 return TEST_OK;
1574 }
1575
1576 static int test__hybrid_group_modifier1(struct evlist *evlist)
1577 {
1578 struct evsel *evsel, *leader;
1579
1580 evsel = leader = evlist__first(evlist);
1581 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1582 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1583 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1584 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1585 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1586 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1587
1588 evsel = evsel__next(evsel);
1589 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1590 TEST_ASSERT_VAL("wrong config", 0xc0 == evsel->core.attr.config);
1591 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1592 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1593 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1594 return TEST_OK;
1595 }
1596
1597 static int test__hybrid_raw1(struct evlist *evlist)
1598 {
1599 struct evsel *evsel = evlist__first(evlist);
1600
1601 if (!perf_pmu__hybrid_mounted("cpu_atom")) {
1602 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1603 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1604 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1605 return TEST_OK;
1606 }
1607
1608 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1609 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1610 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1611
1612
1613 evsel = evsel__next(evsel);
1614 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1615 return TEST_OK;
1616 }
1617
1618 static int test__hybrid_raw2(struct evlist *evlist)
1619 {
1620 struct evsel *evsel = evlist__first(evlist);
1621
1622 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1623 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1624 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1625 return TEST_OK;
1626 }
1627
1628 static int test__hybrid_cache_event(struct evlist *evlist)
1629 {
1630 struct evsel *evsel = evlist__first(evlist);
1631
1632 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1633 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
1634 TEST_ASSERT_VAL("wrong config", 0x2 == (evsel->core.attr.config & 0xffffffff));
1635 return TEST_OK;
1636 }
1637
1638 struct evlist_test {
1639 const char *name;
1640 bool (*valid)(void);
1641 int (*check)(struct evlist *evlist);
1642 };
1643
1644 static const struct evlist_test test__events[] = {
1645 {
1646 .name = "syscalls:sys_enter_openat",
1647 .check = test__checkevent_tracepoint,
1648
1649 },
1650 {
1651 .name = "syscalls:*",
1652 .check = test__checkevent_tracepoint_multi,
1653
1654 },
1655 {
1656 .name = "r1a",
1657 .check = test__checkevent_raw,
1658
1659 },
1660 {
1661 .name = "1:1",
1662 .check = test__checkevent_numeric,
1663
1664 },
1665 {
1666 .name = "instructions",
1667 .check = test__checkevent_symbolic_name,
1668
1669 },
1670 {
1671 .name = "cycles/period=100000,config2/",
1672 .check = test__checkevent_symbolic_name_config,
1673
1674 },
1675 {
1676 .name = "faults",
1677 .check = test__checkevent_symbolic_alias,
1678
1679 },
1680 {
1681 .name = "L1-dcache-load-miss",
1682 .check = test__checkevent_genhw,
1683
1684 },
1685 {
1686 .name = "mem:0",
1687 .check = test__checkevent_breakpoint,
1688
1689 },
1690 {
1691 .name = "mem:0:x",
1692 .check = test__checkevent_breakpoint_x,
1693
1694 },
1695 {
1696 .name = "mem:0:r",
1697 .check = test__checkevent_breakpoint_r,
1698
1699 },
1700 {
1701 .name = "mem:0:w",
1702 .check = test__checkevent_breakpoint_w,
1703
1704 },
1705 {
1706 .name = "syscalls:sys_enter_openat:k",
1707 .check = test__checkevent_tracepoint_modifier,
1708
1709 },
1710 {
1711 .name = "syscalls:*:u",
1712 .check = test__checkevent_tracepoint_multi_modifier,
1713
1714 },
1715 {
1716 .name = "r1a:kp",
1717 .check = test__checkevent_raw_modifier,
1718
1719 },
1720 {
1721 .name = "1:1:hp",
1722 .check = test__checkevent_numeric_modifier,
1723
1724 },
1725 {
1726 .name = "instructions:h",
1727 .check = test__checkevent_symbolic_name_modifier,
1728
1729 },
1730 {
1731 .name = "faults:u",
1732 .check = test__checkevent_symbolic_alias_modifier,
1733
1734 },
1735 {
1736 .name = "L1-dcache-load-miss:kp",
1737 .check = test__checkevent_genhw_modifier,
1738
1739 },
1740 {
1741 .name = "mem:0:u",
1742 .check = test__checkevent_breakpoint_modifier,
1743
1744 },
1745 {
1746 .name = "mem:0:x:k",
1747 .check = test__checkevent_breakpoint_x_modifier,
1748
1749 },
1750 {
1751 .name = "mem:0:r:hp",
1752 .check = test__checkevent_breakpoint_r_modifier,
1753
1754 },
1755 {
1756 .name = "mem:0:w:up",
1757 .check = test__checkevent_breakpoint_w_modifier,
1758
1759 },
1760 {
1761 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1762 .check = test__checkevent_list,
1763
1764 },
1765 {
1766 .name = "instructions:G",
1767 .check = test__checkevent_exclude_host_modifier,
1768
1769 },
1770 {
1771 .name = "instructions:H",
1772 .check = test__checkevent_exclude_guest_modifier,
1773
1774 },
1775 {
1776 .name = "mem:0:rw",
1777 .check = test__checkevent_breakpoint_rw,
1778
1779 },
1780 {
1781 .name = "mem:0:rw:kp",
1782 .check = test__checkevent_breakpoint_rw_modifier,
1783
1784 },
1785 {
1786 .name = "{instructions:k,cycles:upp}",
1787 .check = test__group1,
1788
1789 },
1790 {
1791 .name = "{faults:k,cache-references}:u,cycles:k",
1792 .check = test__group2,
1793
1794 },
1795 {
1796 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1797 .check = test__group3,
1798
1799 },
1800 {
1801 .name = "{cycles:u,instructions:kp}:p",
1802 .check = test__group4,
1803
1804 },
1805 {
1806 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1807 .check = test__group5,
1808
1809 },
1810 {
1811 .name = "*:*",
1812 .check = test__all_tracepoints,
1813
1814 },
1815 {
1816 .name = "{cycles,cache-misses:G}:H",
1817 .check = test__group_gh1,
1818
1819 },
1820 {
1821 .name = "{cycles,cache-misses:H}:G",
1822 .check = test__group_gh2,
1823
1824 },
1825 {
1826 .name = "{cycles:G,cache-misses:H}:u",
1827 .check = test__group_gh3,
1828
1829 },
1830 {
1831 .name = "{cycles:G,cache-misses:H}:uG",
1832 .check = test__group_gh4,
1833
1834 },
1835 {
1836 .name = "{cycles,cache-misses,branch-misses}:S",
1837 .check = test__leader_sample1,
1838
1839 },
1840 {
1841 .name = "{instructions,branch-misses}:Su",
1842 .check = test__leader_sample2,
1843
1844 },
1845 {
1846 .name = "instructions:uDp",
1847 .check = test__checkevent_pinned_modifier,
1848
1849 },
1850 {
1851 .name = "{cycles,cache-misses,branch-misses}:D",
1852 .check = test__pinned_group,
1853
1854 },
1855 {
1856 .name = "mem:0/1",
1857 .check = test__checkevent_breakpoint_len,
1858
1859 },
1860 {
1861 .name = "mem:0/2:w",
1862 .check = test__checkevent_breakpoint_len_w,
1863
1864 },
1865 {
1866 .name = "mem:0/4:rw:u",
1867 .check = test__checkevent_breakpoint_len_rw_modifier,
1868
1869 },
1870 #if defined(__s390x__)
1871 {
1872 .name = "kvm-s390:kvm_s390_create_vm",
1873 .check = test__checkevent_tracepoint,
1874 .valid = kvm_s390_create_vm_valid,
1875
1876 },
1877 #endif
1878 {
1879 .name = "instructions:I",
1880 .check = test__checkevent_exclude_idle_modifier,
1881
1882 },
1883 {
1884 .name = "instructions:kIG",
1885 .check = test__checkevent_exclude_idle_modifier_1,
1886
1887 },
1888 {
1889 .name = "task-clock:P,cycles",
1890 .check = test__checkevent_precise_max_modifier,
1891
1892 },
1893 {
1894 .name = "instructions/name=insn/",
1895 .check = test__checkevent_config_symbol,
1896
1897 },
1898 {
1899 .name = "r1234/name=rawpmu/",
1900 .check = test__checkevent_config_raw,
1901
1902 },
1903 {
1904 .name = "4:0x6530160/name=numpmu/",
1905 .check = test__checkevent_config_num,
1906
1907 },
1908 {
1909 .name = "L1-dcache-misses/name=cachepmu/",
1910 .check = test__checkevent_config_cache,
1911
1912 },
1913 {
1914 .name = "intel_pt//u",
1915 .valid = test__intel_pt_valid,
1916 .check = test__intel_pt,
1917
1918 },
1919 {
1920 .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",
1921 .check = test__checkevent_complex_name,
1922
1923 },
1924 {
1925 .name = "cycles//u",
1926 .check = test__sym_event_slash,
1927
1928 },
1929 {
1930 .name = "cycles:k",
1931 .check = test__sym_event_dc,
1932
1933 },
1934 {
1935 .name = "instructions:uep",
1936 .check = test__checkevent_exclusive_modifier,
1937
1938 },
1939 {
1940 .name = "{cycles,cache-misses,branch-misses}:e",
1941 .check = test__exclusive_group,
1942
1943 },
1944 };
1945
1946 static const struct evlist_test test__events_pmu[] = {
1947 {
1948 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1949 .check = test__checkevent_pmu,
1950
1951 },
1952 {
1953 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1954 .check = test__checkevent_pmu_name,
1955
1956 },
1957 {
1958 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1959 .check = test__checkevent_pmu_partial_time_callgraph,
1960
1961 },
1962 {
1963 .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
1964 .check = test__checkevent_complex_name,
1965
1966 },
1967 {
1968 .name = "software/r1a/",
1969 .check = test__checkevent_raw_pmu,
1970
1971 },
1972 {
1973 .name = "software/r0x1a/",
1974 .check = test__checkevent_raw_pmu,
1975
1976 },
1977 };
1978
1979 struct terms_test {
1980 const char *str;
1981 int (*check)(struct list_head *terms);
1982 };
1983
1984 static const struct terms_test test__terms[] = {
1985 [0] = {
1986 .str = "config=10,config1,config2=3,umask=1,read,r0xead",
1987 .check = test__checkterms_simple,
1988 },
1989 };
1990
1991 static const struct evlist_test test__hybrid_events[] = {
1992 {
1993 .name = "cpu_core/cpu-cycles/",
1994 .check = test__hybrid_hw_event_with_pmu,
1995
1996 },
1997 {
1998 .name = "{cpu_core/cpu-cycles/,cpu_core/instructions/}",
1999 .check = test__hybrid_hw_group_event,
2000
2001 },
2002 {
2003 .name = "{cpu-clock,cpu_core/cpu-cycles/}",
2004 .check = test__hybrid_sw_hw_group_event,
2005
2006 },
2007 {
2008 .name = "{cpu_core/cpu-cycles/,cpu-clock}",
2009 .check = test__hybrid_hw_sw_group_event,
2010
2011 },
2012 {
2013 .name = "{cpu_core/cpu-cycles/k,cpu_core/instructions/u}",
2014 .check = test__hybrid_group_modifier1,
2015
2016 },
2017 {
2018 .name = "r1a",
2019 .check = test__hybrid_raw1,
2020
2021 },
2022 {
2023 .name = "cpu_core/r1a/",
2024 .check = test__hybrid_raw2,
2025
2026 },
2027 {
2028 .name = "cpu_core/config=10,config1,config2=3,period=1000/u",
2029 .check = test__checkevent_pmu,
2030
2031 },
2032 {
2033 .name = "cpu_core/LLC-loads/",
2034 .check = test__hybrid_cache_event,
2035
2036 },
2037 };
2038
2039 static int test_event(const struct evlist_test *e)
2040 {
2041 struct parse_events_error err;
2042 struct evlist *evlist;
2043 int ret;
2044
2045 if (e->valid && !e->valid()) {
2046 pr_debug("... SKIP\n");
2047 return TEST_OK;
2048 }
2049
2050 evlist = evlist__new();
2051 if (evlist == NULL) {
2052 pr_err("Failed allocation");
2053 return TEST_FAIL;
2054 }
2055 parse_events_error__init(&err);
2056 ret = parse_events(evlist, e->name, &err);
2057 if (ret) {
2058 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2059 e->name, ret, err.str);
2060 parse_events_error__print(&err, e->name);
2061 ret = TEST_FAIL;
2062 if (strstr(err.str, "can't access trace events"))
2063 ret = TEST_SKIP;
2064 } else {
2065 ret = e->check(evlist);
2066 }
2067 parse_events_error__exit(&err);
2068 evlist__delete(evlist);
2069
2070 return ret;
2071 }
2072
2073 static int test_event_fake_pmu(const char *str)
2074 {
2075 struct parse_events_error err;
2076 struct evlist *evlist;
2077 int ret;
2078
2079 evlist = evlist__new();
2080 if (!evlist)
2081 return -ENOMEM;
2082
2083 parse_events_error__init(&err);
2084 perf_pmu__test_parse_init();
2085 ret = __parse_events(evlist, str, &err, &perf_pmu__fake);
2086 if (ret) {
2087 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2088 str, ret, err.str);
2089 parse_events_error__print(&err, str);
2090 }
2091
2092 parse_events_error__exit(&err);
2093 evlist__delete(evlist);
2094
2095 return ret;
2096 }
2097
2098 static int combine_test_results(int existing, int latest)
2099 {
2100 if (existing == TEST_FAIL)
2101 return TEST_FAIL;
2102 if (existing == TEST_SKIP)
2103 return latest == TEST_OK ? TEST_SKIP : latest;
2104 return latest;
2105 }
2106
2107 static int test_events(const struct evlist_test *events, int cnt)
2108 {
2109 int ret = TEST_OK;
2110
2111 for (int i = 0; i < cnt; i++) {
2112 const struct evlist_test *e = &events[i];
2113 int test_ret;
2114
2115 pr_debug("running test %d '%s'\n", i, e->name);
2116 test_ret = test_event(e);
2117 if (test_ret != TEST_OK) {
2118 pr_debug("Event test failure: test %d '%s'", i, e->name);
2119 ret = combine_test_results(ret, test_ret);
2120 }
2121 }
2122
2123 return ret;
2124 }
2125
2126 static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2127 {
2128 return test_events(test__events, ARRAY_SIZE(test__events));
2129 }
2130
2131 static int test_term(const struct terms_test *t)
2132 {
2133 struct list_head terms;
2134 int ret;
2135
2136 INIT_LIST_HEAD(&terms);
2137
2138
2139
2140
2141
2142 if (perf_pmu__test_parse_init())
2143 return -1;
2144
2145 ret = parse_events_terms(&terms, t->str);
2146 if (ret) {
2147 pr_debug("failed to parse terms '%s', err %d\n",
2148 t->str , ret);
2149 return ret;
2150 }
2151
2152 ret = t->check(&terms);
2153 parse_events_terms__purge(&terms);
2154
2155 return ret;
2156 }
2157
2158 static int test_terms(const struct terms_test *terms, int cnt)
2159 {
2160 int ret = 0;
2161
2162 for (int i = 0; i < cnt; i++) {
2163 const struct terms_test *t = &terms[i];
2164
2165 pr_debug("running test %d '%s'\n", i, t->str);
2166 ret = test_term(t);
2167 if (ret)
2168 break;
2169 }
2170
2171 return ret;
2172 }
2173
2174 static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2175 {
2176 return test_terms(test__terms, ARRAY_SIZE(test__terms));
2177 }
2178
2179 static int test_pmu(void)
2180 {
2181 struct stat st;
2182 char path[PATH_MAX];
2183 int ret;
2184
2185 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
2186 sysfs__mountpoint());
2187
2188 ret = stat(path, &st);
2189 if (ret)
2190 pr_debug("omitting PMU cpu tests\n");
2191 return !ret;
2192 }
2193
2194 static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2195 {
2196 struct stat st;
2197 char path[PATH_MAX];
2198 struct dirent *ent;
2199 DIR *dir;
2200 int ret;
2201
2202 if (!test_pmu())
2203 return TEST_SKIP;
2204
2205 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
2206 sysfs__mountpoint());
2207
2208 ret = stat(path, &st);
2209 if (ret) {
2210 pr_debug("omitting PMU cpu events tests: %s\n", path);
2211 return TEST_OK;
2212 }
2213
2214 dir = opendir(path);
2215 if (!dir) {
2216 pr_debug("can't open pmu event dir: %s\n", path);
2217 return TEST_FAIL;
2218 }
2219
2220 ret = TEST_OK;
2221 while ((ent = readdir(dir))) {
2222 struct evlist_test e = { .name = NULL, };
2223 char name[2 * NAME_MAX + 1 + 12 + 3];
2224 int test_ret;
2225
2226
2227 if (strchr(ent->d_name, '.'))
2228 continue;
2229
2230 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
2231
2232 e.name = name;
2233 e.check = test__checkevent_pmu_events;
2234
2235 test_ret = test_event(&e);
2236 if (test_ret != TEST_OK) {
2237 pr_debug("Test PMU event failed for '%s'", name);
2238 ret = combine_test_results(ret, test_ret);
2239 }
2240 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
2241 e.name = name;
2242 e.check = test__checkevent_pmu_events_mix;
2243 test_ret = test_event(&e);
2244 if (test_ret != TEST_OK) {
2245 pr_debug("Test PMU event failed for '%s'", name);
2246 ret = combine_test_results(ret, test_ret);
2247 }
2248 }
2249
2250 closedir(dir);
2251 return ret;
2252 }
2253
2254 static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2255 {
2256 if (!test_pmu())
2257 return TEST_SKIP;
2258
2259 return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
2260 }
2261
2262 static bool test_alias(char **event, char **alias)
2263 {
2264 char path[PATH_MAX];
2265 DIR *dir;
2266 struct dirent *dent;
2267 const char *sysfs = sysfs__mountpoint();
2268 char buf[128];
2269 FILE *file;
2270
2271 if (!sysfs)
2272 return false;
2273
2274 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs);
2275 dir = opendir(path);
2276 if (!dir)
2277 return false;
2278
2279 while ((dent = readdir(dir))) {
2280 if (!strcmp(dent->d_name, ".") ||
2281 !strcmp(dent->d_name, ".."))
2282 continue;
2283
2284 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias",
2285 sysfs, dent->d_name);
2286
2287 if (!file_available(path))
2288 continue;
2289
2290 file = fopen(path, "r");
2291 if (!file)
2292 continue;
2293
2294 if (!fgets(buf, sizeof(buf), file)) {
2295 fclose(file);
2296 continue;
2297 }
2298
2299
2300 buf[strlen(buf) - 1] = 0;
2301
2302 fclose(file);
2303 *event = strdup(dent->d_name);
2304 *alias = strdup(buf);
2305 closedir(dir);
2306
2307 if (*event == NULL || *alias == NULL) {
2308 free(*event);
2309 free(*alias);
2310 return false;
2311 }
2312
2313 return true;
2314 }
2315
2316 closedir(dir);
2317 return false;
2318 }
2319
2320 static int test__hybrid(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2321 {
2322 if (!perf_pmu__has_hybrid())
2323 return TEST_SKIP;
2324
2325 return test_events(test__hybrid_events, ARRAY_SIZE(test__hybrid_events));
2326 }
2327
2328 static int test__checkevent_pmu_events_alias(struct evlist *evlist)
2329 {
2330 struct evsel *evsel1 = evlist__first(evlist);
2331 struct evsel *evsel2 = evlist__last(evlist);
2332
2333 TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type);
2334 TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config);
2335 return TEST_OK;
2336 }
2337
2338 static int test__pmu_events_alias(char *event, char *alias)
2339 {
2340 struct evlist_test e = { .name = NULL, };
2341 char name[2 * NAME_MAX + 20];
2342
2343 snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/",
2344 event, alias);
2345
2346 e.name = name;
2347 e.check = test__checkevent_pmu_events_alias;
2348 return test_event(&e);
2349 }
2350
2351 static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2352 {
2353 char *event, *alias;
2354 int ret;
2355
2356 if (!test_alias(&event, &alias))
2357 return TEST_SKIP;
2358
2359 ret = test__pmu_events_alias(event, alias);
2360
2361 free(event);
2362 free(alias);
2363 return ret;
2364 }
2365
2366 static int test__pmu_events_alias2(struct test_suite *test __maybe_unused,
2367 int subtest __maybe_unused)
2368 {
2369 static const char events[][30] = {
2370 "event-hyphen",
2371 "event-two-hyph",
2372 };
2373 int ret = TEST_OK;
2374
2375 for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) {
2376 int test_ret = test_event_fake_pmu(&events[i][0]);
2377
2378 if (test_ret != TEST_OK) {
2379 pr_debug("check_parse_fake %s failed\n", &events[i][0]);
2380 ret = combine_test_results(ret, test_ret);
2381 }
2382 }
2383
2384 return ret;
2385 }
2386
2387 static struct test_case tests__parse_events[] = {
2388 TEST_CASE_REASON("Test event parsing",
2389 events2,
2390 "permissions"),
2391 TEST_CASE_REASON("Test parsing of \"hybrid\" CPU events",
2392 hybrid,
2393 "not hybrid"),
2394 TEST_CASE_REASON("Parsing of all PMU events from sysfs",
2395 pmu_events,
2396 "permissions"),
2397 TEST_CASE_REASON("Parsing of given PMU events from sysfs",
2398 pmu_events2,
2399 "permissions"),
2400 TEST_CASE_REASON("Parsing of aliased events from sysfs", alias,
2401 "no aliases in sysfs"),
2402 TEST_CASE("Parsing of aliased events", pmu_events_alias2),
2403 TEST_CASE("Parsing of terms (event modifiers)", terms2),
2404 { .name = NULL, }
2405 };
2406
2407 struct test_suite suite__parse_events = {
2408 .desc = "Parse event definition strings",
2409 .test_cases = tests__parse_events,
2410 };