evsel-roundtrip-name.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "evlist.h"
  2. #include "evsel.h"
  3. #include "parse-events.h"
  4. #include "tests.h"
  5. #include "debug.h"
  6. static int perf_evsel__roundtrip_cache_name_test(void)
  7. {
  8. char name[128];
  9. int type, op, err = 0, ret = 0, i, idx;
  10. struct perf_evsel *evsel;
  11. struct perf_evlist *evlist = perf_evlist__new();
  12. if (evlist == NULL)
  13. return -ENOMEM;
  14. for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
  15. for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
  16. /* skip invalid cache type */
  17. if (!perf_evsel__is_cache_op_valid(type, op))
  18. continue;
  19. for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
  20. __perf_evsel__hw_cache_type_op_res_name(type, op, i,
  21. name, sizeof(name));
  22. err = parse_events(evlist, name, NULL);
  23. if (err)
  24. ret = err;
  25. }
  26. }
  27. }
  28. idx = 0;
  29. evsel = perf_evlist__first(evlist);
  30. for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
  31. for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
  32. /* skip invalid cache type */
  33. if (!perf_evsel__is_cache_op_valid(type, op))
  34. continue;
  35. for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
  36. __perf_evsel__hw_cache_type_op_res_name(type, op, i,
  37. name, sizeof(name));
  38. if (evsel->idx != idx)
  39. continue;
  40. ++idx;
  41. if (strcmp(perf_evsel__name(evsel), name)) {
  42. pr_debug("%s != %s\n", perf_evsel__name(evsel), name);
  43. ret = -1;
  44. }
  45. evsel = perf_evsel__next(evsel);
  46. }
  47. }
  48. }
  49. perf_evlist__delete(evlist);
  50. return ret;
  51. }
  52. static int __perf_evsel__name_array_test(const char *names[], int nr_names)
  53. {
  54. int i, err;
  55. struct perf_evsel *evsel;
  56. struct perf_evlist *evlist = perf_evlist__new();
  57. if (evlist == NULL)
  58. return -ENOMEM;
  59. for (i = 0; i < nr_names; ++i) {
  60. err = parse_events(evlist, names[i], NULL);
  61. if (err) {
  62. pr_debug("failed to parse event '%s', err %d\n",
  63. names[i], err);
  64. goto out_delete_evlist;
  65. }
  66. }
  67. err = 0;
  68. evlist__for_each_entry(evlist, evsel) {
  69. if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
  70. --err;
  71. pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);
  72. }
  73. }
  74. out_delete_evlist:
  75. perf_evlist__delete(evlist);
  76. return err;
  77. }
  78. #define perf_evsel__name_array_test(names) \
  79. __perf_evsel__name_array_test(names, ARRAY_SIZE(names))
  80. int test__perf_evsel__roundtrip_name_test(int subtest __maybe_unused)
  81. {
  82. int err = 0, ret = 0;
  83. err = perf_evsel__name_array_test(perf_evsel__hw_names);
  84. if (err)
  85. ret = err;
  86. err = __perf_evsel__name_array_test(perf_evsel__sw_names,
  87. PERF_COUNT_SW_DUMMY + 1);
  88. if (err)
  89. ret = err;
  90. err = perf_evsel__roundtrip_cache_name_test();
  91. if (err)
  92. ret = err;
  93. return ret;
  94. }