1 // SPDX-License-Identifier: GPL-2.0
4 #include "parse-events.h"
7 #include <linux/kernel.h>
9 static int perf_evsel__roundtrip_cache_name_test(void)
13 for (int type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
14 for (int op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
15 /* skip invalid cache type */
16 if (!evsel__is_cache_op_valid(type
, op
))
19 for (int res
= 0; res
< PERF_COUNT_HW_CACHE_RESULT_MAX
; res
++) {
21 struct evlist
*evlist
= evlist__new();
26 pr_debug("Failed to alloc evlist");
29 __evsel__hw_cache_type_op_res_name(type
, op
, res
,
32 err
= parse_event(evlist
, name
);
34 pr_debug("Failure to parse cache event '%s' possibly as PMUs don't support it",
36 evlist__delete(evlist
);
39 evlist__for_each_entry(evlist
, evsel
) {
40 if (!evsel__name_is(evsel
, name
)) {
41 pr_debug("%s != %s\n", evsel__name(evsel
), name
);
45 evlist__delete(evlist
);
52 static int perf_evsel__name_array_test(const char *const names
[], int nr_names
)
56 for (int i
= 0; i
< nr_names
; ++i
) {
57 struct evlist
*evlist
= evlist__new();
62 pr_debug("Failed to alloc evlist");
65 err
= parse_event(evlist
, names
[i
]);
67 pr_debug("failed to parse event '%s', err %d\n",
69 evlist__delete(evlist
);
73 evlist__for_each_entry(evlist
, evsel
) {
74 if (!evsel__name_is(evsel
, names
[i
])) {
75 pr_debug("%s != %s\n", evsel__name(evsel
), names
[i
]);
79 evlist__delete(evlist
);
84 static int test__perf_evsel__roundtrip_name_test(struct test_suite
*test __maybe_unused
,
85 int subtest __maybe_unused
)
87 int err
= 0, ret
= TEST_OK
;
89 err
= perf_evsel__name_array_test(evsel__hw_names
, PERF_COUNT_HW_MAX
);
93 err
= perf_evsel__name_array_test(evsel__sw_names
, PERF_COUNT_SW_DUMMY
+ 1);
97 err
= perf_evsel__roundtrip_cache_name_test();
104 DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test
);