1 // SPDX-License-Identifier: GPL-2.0
4 #include "parse-events.h"
8 #include "pmu-hybrid.h"
10 #include <linux/kernel.h>
12 static int perf_evsel__roundtrip_cache_name_test(void)
15 int type, op, err = 0, ret = 0, i, idx;
17 struct evlist *evlist = evlist__new();
22 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
23 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
24 /* skip invalid cache type */
25 if (!evsel__is_cache_op_valid(type, op))
28 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
29 __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
30 err = parse_events(evlist, name, NULL);
38 evsel = evlist__first(evlist);
40 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
41 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
42 /* skip invalid cache type */
43 if (!evsel__is_cache_op_valid(type, op))
46 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
47 __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name));
48 if (evsel->core.idx != idx)
53 if (strcmp(evsel__name(evsel), name)) {
54 pr_debug("%s != %s\n", evsel__name(evsel), name);
58 evsel = evsel__next(evsel);
63 evlist__delete(evlist);
67 static int __perf_evsel__name_array_test(const char *names[], int nr_names,
72 struct evlist *evlist = evlist__new();
77 for (i = 0; i < nr_names; ++i) {
78 err = parse_events(evlist, names[i], NULL);
80 pr_debug("failed to parse event '%s', err %d\n",
82 goto out_delete_evlist;
87 evlist__for_each_entry(evlist, evsel) {
88 if (strcmp(evsel__name(evsel), names[evsel->core.idx / distance])) {
90 pr_debug("%s != %s\n", evsel__name(evsel), names[evsel->core.idx / distance]);
95 evlist__delete(evlist);
99 #define perf_evsel__name_array_test(names, distance) \
100 __perf_evsel__name_array_test(names, ARRAY_SIZE(names), distance)
102 int test__perf_evsel__roundtrip_name_test(struct test *test __maybe_unused, int subtest __maybe_unused)
104 int err = 0, ret = 0;
106 if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom"))
107 return perf_evsel__name_array_test(evsel__hw_names, 2);
109 err = perf_evsel__name_array_test(evsel__hw_names, 1);
113 err = __perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1, 1);
117 err = perf_evsel__roundtrip_cache_name_test();