1 // SPDX-License-Identifier: GPL-2.0
4 #include "parse-events.h"
8 #include <linux/kernel.h>
10 static int perf_evsel__roundtrip_cache_name_test(void)
13 int type
, op
, err
= 0, ret
= 0, i
, idx
;
15 struct evlist
*evlist
= evlist__new();
20 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
21 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
22 /* skip invalid cache type */
23 if (!perf_evsel__is_cache_op_valid(type
, op
))
26 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
27 __perf_evsel__hw_cache_type_op_res_name(type
, op
, i
,
29 err
= parse_events(evlist
, name
, NULL
);
37 evsel
= evlist__first(evlist
);
39 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
40 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
41 /* skip invalid cache type */
42 if (!perf_evsel__is_cache_op_valid(type
, op
))
45 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
46 __perf_evsel__hw_cache_type_op_res_name(type
, op
, i
,
48 if (evsel
->idx
!= idx
)
53 if (strcmp(perf_evsel__name(evsel
), name
)) {
54 pr_debug("%s != %s\n", perf_evsel__name(evsel
), name
);
58 evsel
= perf_evsel__next(evsel
);
63 evlist__delete(evlist
);
67 static int __perf_evsel__name_array_test(const char *names
[], int nr_names
)
71 struct evlist
*evlist
= evlist__new();
76 for (i
= 0; i
< nr_names
; ++i
) {
77 err
= parse_events(evlist
, names
[i
], NULL
);
79 pr_debug("failed to parse event '%s', err %d\n",
81 goto out_delete_evlist
;
86 evlist__for_each_entry(evlist
, evsel
) {
87 if (strcmp(perf_evsel__name(evsel
), names
[evsel
->idx
])) {
89 pr_debug("%s != %s\n", perf_evsel__name(evsel
), names
[evsel
->idx
]);
94 evlist__delete(evlist
);
98 #define perf_evsel__name_array_test(names) \
99 __perf_evsel__name_array_test(names, ARRAY_SIZE(names))
101 int test__perf_evsel__roundtrip_name_test(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
103 int err
= 0, ret
= 0;
105 err
= perf_evsel__name_array_test(perf_evsel__hw_names
);
109 err
= __perf_evsel__name_array_test(perf_evsel__sw_names
,
110 PERF_COUNT_SW_DUMMY
+ 1);
114 err
= perf_evsel__roundtrip_cache_name_test();