pmu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "evlist.h"
  3. #include "evsel.h"
  4. #include "parse-events.h"
  5. #include "pmu.h"
  6. #include "pmus.h"
  7. #include "tests.h"
  8. #include "debug.h"
  9. #include "fncache.h"
  10. #include <api/fs/fs.h>
  11. #include <ctype.h>
  12. #include <dirent.h>
  13. #include <errno.h>
  14. #include <fcntl.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <sys/stat.h>
  19. #include <sys/types.h>
  20. /* Cleanup test PMU directory. */
  21. static int test_pmu_put(const char *dir, struct perf_pmu *pmu)
  22. {
  23. char buf[PATH_MAX + 20];
  24. int ret;
  25. if (scnprintf(buf, sizeof(buf), "rm -fr %s", dir) < 0) {
  26. pr_err("Failure to set up buffer for \"%s\"\n", dir);
  27. return -EINVAL;
  28. }
  29. ret = system(buf);
  30. if (ret)
  31. pr_err("Failure to \"%s\"\n", buf);
  32. list_del(&pmu->list);
  33. perf_pmu__delete(pmu);
  34. return ret;
  35. }
  36. /*
  37. * Prepare test PMU directory data, normally exported by kernel at
  38. * /sys/bus/event_source/devices/<pmu>/. Give as input a buffer to hold the file
  39. * path, the result is PMU loaded using that directory.
  40. */
  41. static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
  42. {
  43. /* Simulated format definitions. */
  44. const struct test_format {
  45. const char *name;
  46. const char *value;
  47. } test_formats[] = {
  48. { "krava01", "config:0-1,62-63\n", },
  49. { "krava02", "config:10-17\n", },
  50. { "krava03", "config:5\n", },
  51. { "krava11", "config1:0,2,4,6,8,20-28\n", },
  52. { "krava12", "config1:63\n", },
  53. { "krava13", "config1:45-47\n", },
  54. { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", },
  55. { "krava22", "config2:8,18,48,58\n", },
  56. { "krava23", "config2:28-29,38\n", },
  57. };
  58. const char *test_event = "krava01=15,krava02=170,krava03=1,krava11=27,krava12=1,"
  59. "krava13=2,krava21=119,krava22=11,krava23=2\n";
  60. char name[PATH_MAX];
  61. int dirfd, file;
  62. struct perf_pmu *pmu = NULL;
  63. ssize_t len;
  64. /* Create equivalent of sysfs mount point. */
  65. scnprintf(dir, sz, "/tmp/perf-pmu-test-XXXXXX");
  66. if (!mkdtemp(dir)) {
  67. pr_err("mkdtemp failed\n");
  68. dir[0] = '\0';
  69. return NULL;
  70. }
  71. dirfd = open(dir, O_DIRECTORY);
  72. if (dirfd < 0) {
  73. pr_err("Failed to open test directory \"%s\"\n", dir);
  74. goto err_out;
  75. }
  76. /* Create the test PMU directory and give it a perf_event_attr type number. */
  77. if (mkdirat(dirfd, "perf-pmu-test", 0755) < 0) {
  78. pr_err("Failed to mkdir PMU directory\n");
  79. goto err_out;
  80. }
  81. file = openat(dirfd, "perf-pmu-test/type", O_WRONLY | O_CREAT, 0600);
  82. if (!file) {
  83. pr_err("Failed to open for writing file \"type\"\n");
  84. goto err_out;
  85. }
  86. len = strlen("9999");
  87. if (write(file, "9999\n", len) < len) {
  88. close(file);
  89. pr_err("Failed to write to 'type' file\n");
  90. goto err_out;
  91. }
  92. close(file);
  93. /* Create format directory and files. */
  94. if (mkdirat(dirfd, "perf-pmu-test/format", 0755) < 0) {
  95. pr_err("Failed to mkdir PMU format directory\n)");
  96. goto err_out;
  97. }
  98. for (size_t i = 0; i < ARRAY_SIZE(test_formats); i++) {
  99. const struct test_format *format = &test_formats[i];
  100. if (scnprintf(name, PATH_MAX, "perf-pmu-test/format/%s", format->name) < 0) {
  101. pr_err("Failure to set up path for \"%s\"\n", format->name);
  102. goto err_out;
  103. }
  104. file = openat(dirfd, name, O_WRONLY | O_CREAT, 0600);
  105. if (!file) {
  106. pr_err("Failed to open for writing file \"%s\"\n", name);
  107. goto err_out;
  108. }
  109. if (write(file, format->value, strlen(format->value)) < 0) {
  110. pr_err("Failed to write to file \"%s\"\n", name);
  111. close(file);
  112. goto err_out;
  113. }
  114. close(file);
  115. }
  116. /* Create test event. */
  117. if (mkdirat(dirfd, "perf-pmu-test/events", 0755) < 0) {
  118. pr_err("Failed to mkdir PMU events directory\n");
  119. goto err_out;
  120. }
  121. file = openat(dirfd, "perf-pmu-test/events/test-event", O_WRONLY | O_CREAT, 0600);
  122. if (!file) {
  123. pr_err("Failed to open for writing file \"type\"\n");
  124. goto err_out;
  125. }
  126. len = strlen(test_event);
  127. if (write(file, test_event, len) < len) {
  128. close(file);
  129. pr_err("Failed to write to 'test-event' file\n");
  130. goto err_out;
  131. }
  132. close(file);
  133. /* Make the PMU reading the files created above. */
  134. pmu = perf_pmus__add_test_pmu(dirfd, "perf-pmu-test");
  135. if (!pmu)
  136. pr_err("Test PMU creation failed\n");
  137. err_out:
  138. if (!pmu)
  139. test_pmu_put(dir, pmu);
  140. if (dirfd >= 0)
  141. close(dirfd);
  142. return pmu;
  143. }
  144. static int test__pmu_format(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  145. {
  146. char dir[PATH_MAX];
  147. struct perf_event_attr attr;
  148. struct parse_events_terms terms;
  149. int ret = TEST_FAIL;
  150. struct perf_pmu *pmu = test_pmu_get(dir, sizeof(dir));
  151. if (!pmu)
  152. return TEST_FAIL;
  153. parse_events_terms__init(&terms);
  154. if (parse_events_terms(&terms,
  155. "krava01=15,krava02=170,krava03=1,krava11=27,krava12=1,"
  156. "krava13=2,krava21=119,krava22=11,krava23=2",
  157. NULL)) {
  158. pr_err("Term parsing failed\n");
  159. goto err_out;
  160. }
  161. memset(&attr, 0, sizeof(attr));
  162. ret = perf_pmu__config_terms(pmu, &attr, &terms, /*zero=*/false, /*err=*/NULL);
  163. if (ret) {
  164. pr_err("perf_pmu__config_terms failed");
  165. goto err_out;
  166. }
  167. if (attr.config != 0xc00000000002a823) {
  168. pr_err("Unexpected config value %llx\n", attr.config);
  169. goto err_out;
  170. }
  171. if (attr.config1 != 0x8000400000000145) {
  172. pr_err("Unexpected config1 value %llx\n", attr.config1);
  173. goto err_out;
  174. }
  175. if (attr.config2 != 0x0400000020041d07) {
  176. pr_err("Unexpected config2 value %llx\n", attr.config2);
  177. goto err_out;
  178. }
  179. ret = TEST_OK;
  180. err_out:
  181. parse_events_terms__exit(&terms);
  182. test_pmu_put(dir, pmu);
  183. return ret;
  184. }
  185. static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  186. {
  187. char dir[PATH_MAX];
  188. struct parse_events_error err;
  189. struct evlist *evlist;
  190. struct evsel *evsel;
  191. struct perf_event_attr *attr;
  192. int ret = TEST_FAIL;
  193. struct perf_pmu *pmu = test_pmu_get(dir, sizeof(dir));
  194. const char *event = "perf-pmu-test/test-event/";
  195. if (!pmu)
  196. return TEST_FAIL;
  197. evlist = evlist__new();
  198. if (evlist == NULL) {
  199. pr_err("Failed allocation");
  200. goto err_out;
  201. }
  202. parse_events_error__init(&err);
  203. ret = parse_events(evlist, event, &err);
  204. if (ret) {
  205. pr_debug("failed to parse event '%s', err %d\n", event, ret);
  206. parse_events_error__print(&err, event);
  207. if (parse_events_error__contains(&err, "can't access trace events"))
  208. ret = TEST_SKIP;
  209. goto err_out;
  210. }
  211. evsel = evlist__first(evlist);
  212. attr = &evsel->core.attr;
  213. if (attr->config != 0xc00000000002a823) {
  214. pr_err("Unexpected config value %llx\n", attr->config);
  215. goto err_out;
  216. }
  217. if (attr->config1 != 0x8000400000000145) {
  218. pr_err("Unexpected config1 value %llx\n", attr->config1);
  219. goto err_out;
  220. }
  221. if (attr->config2 != 0x0400000020041d07) {
  222. pr_err("Unexpected config2 value %llx\n", attr->config2);
  223. goto err_out;
  224. }
  225. ret = TEST_OK;
  226. err_out:
  227. parse_events_error__exit(&err);
  228. evlist__delete(evlist);
  229. test_pmu_put(dir, pmu);
  230. return ret;
  231. }
  232. static bool permitted_event_name(const char *name)
  233. {
  234. bool has_lower = false, has_upper = false;
  235. __u64 config;
  236. for (size_t i = 0; i < strlen(name); i++) {
  237. char c = name[i];
  238. if (islower(c)) {
  239. if (has_upper)
  240. goto check_legacy;
  241. has_lower = true;
  242. continue;
  243. }
  244. if (isupper(c)) {
  245. if (has_lower)
  246. goto check_legacy;
  247. has_upper = true;
  248. continue;
  249. }
  250. if (!isdigit(c) && c != '.' && c != '_' && c != '-')
  251. goto check_legacy;
  252. }
  253. return true;
  254. check_legacy:
  255. /*
  256. * If the event name matches a legacy cache name the legacy encoding
  257. * will still be used. This isn't quite WAI as sysfs events should take
  258. * priority, but this case happens on PowerPC and matches the behavior
  259. * in older perf tools where legacy events were the priority. Be
  260. * permissive and assume later PMU drivers will use all lower or upper
  261. * case names.
  262. */
  263. if (parse_events__decode_legacy_cache(name, /*extended_pmu_type=*/0, &config) == 0) {
  264. pr_warning("sysfs event '%s' should be all lower/upper case, it will be matched using legacy encoding.",
  265. name);
  266. return true;
  267. }
  268. return false;
  269. }
  270. static int test__pmu_event_names(struct test_suite *test __maybe_unused,
  271. int subtest __maybe_unused)
  272. {
  273. char path[PATH_MAX];
  274. DIR *pmu_dir, *event_dir;
  275. struct dirent *pmu_dent, *event_dent;
  276. const char *sysfs = sysfs__mountpoint();
  277. int ret = TEST_OK;
  278. if (!sysfs) {
  279. pr_err("Sysfs not mounted\n");
  280. return TEST_FAIL;
  281. }
  282. snprintf(path, sizeof(path), "%s/bus/event_source/devices/", sysfs);
  283. pmu_dir = opendir(path);
  284. if (!pmu_dir) {
  285. pr_err("Error opening \"%s\"\n", path);
  286. return TEST_FAIL;
  287. }
  288. while ((pmu_dent = readdir(pmu_dir))) {
  289. if (!strcmp(pmu_dent->d_name, ".") ||
  290. !strcmp(pmu_dent->d_name, ".."))
  291. continue;
  292. snprintf(path, sizeof(path), "%s/bus/event_source/devices/%s/type",
  293. sysfs, pmu_dent->d_name);
  294. /* Does it look like a PMU? */
  295. if (!file_available(path))
  296. continue;
  297. /* Process events. */
  298. snprintf(path, sizeof(path), "%s/bus/event_source/devices/%s/events",
  299. sysfs, pmu_dent->d_name);
  300. event_dir = opendir(path);
  301. if (!event_dir) {
  302. pr_debug("Skipping as no event directory \"%s\"\n", path);
  303. continue;
  304. }
  305. while ((event_dent = readdir(event_dir))) {
  306. const char *event_name = event_dent->d_name;
  307. if (!strcmp(event_name, ".") || !strcmp(event_name, ".."))
  308. continue;
  309. if (!permitted_event_name(event_name)) {
  310. pr_err("Invalid sysfs event name: %s/%s\n",
  311. pmu_dent->d_name, event_name);
  312. ret = TEST_FAIL;
  313. }
  314. }
  315. closedir(event_dir);
  316. }
  317. closedir(pmu_dir);
  318. return ret;
  319. }
  320. static const char * const uncore_chas[] = {
  321. "uncore_cha_0",
  322. "uncore_cha_1",
  323. "uncore_cha_2",
  324. "uncore_cha_3",
  325. "uncore_cha_4",
  326. "uncore_cha_5",
  327. "uncore_cha_6",
  328. "uncore_cha_7",
  329. "uncore_cha_8",
  330. "uncore_cha_9",
  331. "uncore_cha_10",
  332. "uncore_cha_11",
  333. "uncore_cha_12",
  334. "uncore_cha_13",
  335. "uncore_cha_14",
  336. "uncore_cha_15",
  337. "uncore_cha_16",
  338. "uncore_cha_17",
  339. "uncore_cha_18",
  340. "uncore_cha_19",
  341. "uncore_cha_20",
  342. "uncore_cha_21",
  343. "uncore_cha_22",
  344. "uncore_cha_23",
  345. "uncore_cha_24",
  346. "uncore_cha_25",
  347. "uncore_cha_26",
  348. "uncore_cha_27",
  349. "uncore_cha_28",
  350. "uncore_cha_29",
  351. "uncore_cha_30",
  352. "uncore_cha_31",
  353. };
  354. static const char * const mrvl_ddrs[] = {
  355. "mrvl_ddr_pmu_87e1b0000000",
  356. "mrvl_ddr_pmu_87e1b1000000",
  357. "mrvl_ddr_pmu_87e1b2000000",
  358. "mrvl_ddr_pmu_87e1b3000000",
  359. "mrvl_ddr_pmu_87e1b4000000",
  360. "mrvl_ddr_pmu_87e1b5000000",
  361. "mrvl_ddr_pmu_87e1b6000000",
  362. "mrvl_ddr_pmu_87e1b7000000",
  363. "mrvl_ddr_pmu_87e1b8000000",
  364. "mrvl_ddr_pmu_87e1b9000000",
  365. "mrvl_ddr_pmu_87e1ba000000",
  366. "mrvl_ddr_pmu_87e1bb000000",
  367. "mrvl_ddr_pmu_87e1bc000000",
  368. "mrvl_ddr_pmu_87e1bd000000",
  369. "mrvl_ddr_pmu_87e1be000000",
  370. "mrvl_ddr_pmu_87e1bf000000",
  371. };
  372. static int test__name_len(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  373. {
  374. TEST_ASSERT_VAL("cpu", pmu_name_len_no_suffix("cpu") == strlen("cpu"));
  375. TEST_ASSERT_VAL("i915", pmu_name_len_no_suffix("i915") == strlen("i915"));
  376. TEST_ASSERT_VAL("cpum_cf", pmu_name_len_no_suffix("cpum_cf") == strlen("cpum_cf"));
  377. for (size_t i = 0; i < ARRAY_SIZE(uncore_chas); i++) {
  378. TEST_ASSERT_VAL("Strips uncore_cha suffix",
  379. pmu_name_len_no_suffix(uncore_chas[i]) ==
  380. strlen("uncore_cha"));
  381. }
  382. for (size_t i = 0; i < ARRAY_SIZE(mrvl_ddrs); i++) {
  383. TEST_ASSERT_VAL("Strips mrvl_ddr_pmu suffix",
  384. pmu_name_len_no_suffix(mrvl_ddrs[i]) ==
  385. strlen("mrvl_ddr_pmu"));
  386. }
  387. return TEST_OK;
  388. }
  389. static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  390. {
  391. TEST_ASSERT_EQUAL("cpu", pmu_name_cmp("cpu", "cpu"), 0);
  392. TEST_ASSERT_EQUAL("i915", pmu_name_cmp("i915", "i915"), 0);
  393. TEST_ASSERT_EQUAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_cf"), 0);
  394. TEST_ASSERT_VAL("i915", pmu_name_cmp("cpu", "i915") < 0);
  395. TEST_ASSERT_VAL("i915", pmu_name_cmp("i915", "cpu") > 0);
  396. TEST_ASSERT_VAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_ce") > 0);
  397. TEST_ASSERT_VAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_d0") < 0);
  398. for (size_t i = 1; i < ARRAY_SIZE(uncore_chas); i++) {
  399. TEST_ASSERT_VAL("uncore_cha suffixes ordered lt",
  400. pmu_name_cmp(uncore_chas[i-1], uncore_chas[i]) < 0);
  401. TEST_ASSERT_VAL("uncore_cha suffixes ordered gt",
  402. pmu_name_cmp(uncore_chas[i], uncore_chas[i-1]) > 0);
  403. }
  404. for (size_t i = 1; i < ARRAY_SIZE(mrvl_ddrs); i++) {
  405. TEST_ASSERT_VAL("mrvl_ddr_pmu suffixes ordered lt",
  406. pmu_name_cmp(mrvl_ddrs[i-1], mrvl_ddrs[i]) < 0);
  407. TEST_ASSERT_VAL("mrvl_ddr_pmu suffixes ordered gt",
  408. pmu_name_cmp(mrvl_ddrs[i], mrvl_ddrs[i-1]) > 0);
  409. }
  410. return TEST_OK;
  411. }
  412. /**
  413. * Test perf_pmu__match() that's used to search for a PMU given a name passed
  414. * on the command line. The name that's passed may also be a filename type glob
  415. * match. If the name does not match, perf_pmu__match() attempts to match the
  416. * alias of the PMU, if provided.
  417. */
  418. static int test__pmu_match(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  419. {
  420. struct perf_pmu test_pmu = {
  421. .name = "pmuname",
  422. };
  423. TEST_ASSERT_EQUAL("Exact match", perf_pmu__match(&test_pmu, "pmuname"), true);
  424. TEST_ASSERT_EQUAL("Longer token", perf_pmu__match(&test_pmu, "longertoken"), false);
  425. TEST_ASSERT_EQUAL("Shorter token", perf_pmu__match(&test_pmu, "pmu"), false);
  426. test_pmu.name = "pmuname_10";
  427. TEST_ASSERT_EQUAL("Diff suffix_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
  428. TEST_ASSERT_EQUAL("Sub suffix_", perf_pmu__match(&test_pmu, "pmuname_1"), true);
  429. TEST_ASSERT_EQUAL("Same suffix_", perf_pmu__match(&test_pmu, "pmuname_10"), true);
  430. TEST_ASSERT_EQUAL("No suffix_", perf_pmu__match(&test_pmu, "pmuname"), true);
  431. TEST_ASSERT_EQUAL("Underscore_", perf_pmu__match(&test_pmu, "pmuname_"), true);
  432. TEST_ASSERT_EQUAL("Substring_", perf_pmu__match(&test_pmu, "pmuna"), false);
  433. test_pmu.name = "pmuname_ab23";
  434. TEST_ASSERT_EQUAL("Diff suffix hex_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
  435. TEST_ASSERT_EQUAL("Sub suffix hex_", perf_pmu__match(&test_pmu, "pmuname_ab"), true);
  436. TEST_ASSERT_EQUAL("Same suffix hex_", perf_pmu__match(&test_pmu, "pmuname_ab23"), true);
  437. TEST_ASSERT_EQUAL("No suffix hex_", perf_pmu__match(&test_pmu, "pmuname"), true);
  438. TEST_ASSERT_EQUAL("Underscore hex_", perf_pmu__match(&test_pmu, "pmuname_"), true);
  439. TEST_ASSERT_EQUAL("Substring hex_", perf_pmu__match(&test_pmu, "pmuna"), false);
  440. test_pmu.name = "pmuname10";
  441. TEST_ASSERT_EQUAL("Diff suffix", perf_pmu__match(&test_pmu, "pmuname2"), false);
  442. TEST_ASSERT_EQUAL("Sub suffix", perf_pmu__match(&test_pmu, "pmuname1"), true);
  443. TEST_ASSERT_EQUAL("Same suffix", perf_pmu__match(&test_pmu, "pmuname10"), true);
  444. TEST_ASSERT_EQUAL("No suffix", perf_pmu__match(&test_pmu, "pmuname"), true);
  445. TEST_ASSERT_EQUAL("Underscore", perf_pmu__match(&test_pmu, "pmuname_"), false);
  446. TEST_ASSERT_EQUAL("Substring", perf_pmu__match(&test_pmu, "pmuna"), false);
  447. test_pmu.name = "pmunameab23";
  448. TEST_ASSERT_EQUAL("Diff suffix hex", perf_pmu__match(&test_pmu, "pmuname2"), false);
  449. TEST_ASSERT_EQUAL("Sub suffix hex", perf_pmu__match(&test_pmu, "pmunameab"), true);
  450. TEST_ASSERT_EQUAL("Same suffix hex", perf_pmu__match(&test_pmu, "pmunameab23"), true);
  451. TEST_ASSERT_EQUAL("No suffix hex", perf_pmu__match(&test_pmu, "pmuname"), true);
  452. TEST_ASSERT_EQUAL("Underscore hex", perf_pmu__match(&test_pmu, "pmuname_"), false);
  453. TEST_ASSERT_EQUAL("Substring hex", perf_pmu__match(&test_pmu, "pmuna"), false);
  454. /*
  455. * 2 hex chars or less are not considered suffixes so it shouldn't be
  456. * possible to wildcard by skipping the suffix. Therefore there are more
  457. * false results here than above.
  458. */
  459. test_pmu.name = "pmuname_a3";
  460. TEST_ASSERT_EQUAL("Diff suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
  461. /*
  462. * This one should be false, but because pmuname_a3 ends in 3 which is
  463. * decimal, it's not possible to determine if it's a short hex suffix or
  464. * a normal decimal suffix following text. And we want to match on any
  465. * length of decimal suffix. Run the test anyway and expect the wrong
  466. * result. And slightly fuzzy matching shouldn't do too much harm.
  467. */
  468. TEST_ASSERT_EQUAL("Sub suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_a"), true);
  469. TEST_ASSERT_EQUAL("Same suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_a3"), true);
  470. TEST_ASSERT_EQUAL("No suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname"), false);
  471. TEST_ASSERT_EQUAL("Underscore 2 hex_", perf_pmu__match(&test_pmu, "pmuname_"), false);
  472. TEST_ASSERT_EQUAL("Substring 2 hex_", perf_pmu__match(&test_pmu, "pmuna"), false);
  473. test_pmu.name = "pmuname_5";
  474. TEST_ASSERT_EQUAL("Glob 1", perf_pmu__match(&test_pmu, "pmu*"), true);
  475. TEST_ASSERT_EQUAL("Glob 2", perf_pmu__match(&test_pmu, "nomatch*"), false);
  476. TEST_ASSERT_EQUAL("Seq 1", perf_pmu__match(&test_pmu, "pmuname_[12345]"), true);
  477. TEST_ASSERT_EQUAL("Seq 2", perf_pmu__match(&test_pmu, "pmuname_[67890]"), false);
  478. TEST_ASSERT_EQUAL("? 1", perf_pmu__match(&test_pmu, "pmuname_?"), true);
  479. TEST_ASSERT_EQUAL("? 2", perf_pmu__match(&test_pmu, "pmuname_1?"), false);
  480. return TEST_OK;
  481. }
  482. static struct test_case tests__pmu[] = {
  483. TEST_CASE("Parsing with PMU format directory", pmu_format),
  484. TEST_CASE("Parsing with PMU event", pmu_events),
  485. TEST_CASE("PMU event names", pmu_event_names),
  486. TEST_CASE("PMU name combining", name_len),
  487. TEST_CASE("PMU name comparison", name_cmp),
  488. TEST_CASE("PMU cmdline match", pmu_match),
  489. { .name = NULL, }
  490. };
  491. struct test_suite suite__pmu = {
  492. .desc = "Sysfs PMU tests",
  493. .test_cases = tests__pmu,
  494. };