3 #include "parse-events.h"
7 static int perf_evsel__roundtrip_cache_name_test(void)
10 int type
, op
, err
= 0, ret
= 0, i
, idx
;
11 struct perf_evsel
*evsel
;
12 struct perf_evlist
*evlist
= perf_evlist__new();
17 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
18 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
19 /* skip invalid cache type */
20 if (!perf_evsel__is_cache_op_valid(type
, op
))
23 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
24 __perf_evsel__hw_cache_type_op_res_name(type
, op
, i
,
26 err
= parse_events(evlist
, name
, NULL
);
34 evsel
= perf_evlist__first(evlist
);
36 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
37 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
38 /* skip invalid cache type */
39 if (!perf_evsel__is_cache_op_valid(type
, op
))
42 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
43 __perf_evsel__hw_cache_type_op_res_name(type
, op
, i
,
45 if (evsel
->idx
!= idx
)
50 if (strcmp(perf_evsel__name(evsel
), name
)) {
51 pr_debug("%s != %s\n", perf_evsel__name(evsel
), name
);
55 evsel
= perf_evsel__next(evsel
);
60 perf_evlist__delete(evlist
);
64 static int __perf_evsel__name_array_test(const char *names
[], int nr_names
)
67 struct perf_evsel
*evsel
;
68 struct perf_evlist
*evlist
= perf_evlist__new();
73 for (i
= 0; i
< nr_names
; ++i
) {
74 err
= parse_events(evlist
, names
[i
], NULL
);
76 pr_debug("failed to parse event '%s', err %d\n",
78 goto out_delete_evlist
;
83 evlist__for_each(evlist
, evsel
) {
84 if (strcmp(perf_evsel__name(evsel
), names
[evsel
->idx
])) {
86 pr_debug("%s != %s\n", perf_evsel__name(evsel
), names
[evsel
->idx
]);
91 perf_evlist__delete(evlist
);
95 #define perf_evsel__name_array_test(names) \
96 __perf_evsel__name_array_test(names, ARRAY_SIZE(names))
98 int test__perf_evsel__roundtrip_name_test(int subtest __maybe_unused
)
100 int err
= 0, ret
= 0;
102 err
= perf_evsel__name_array_test(perf_evsel__hw_names
);
106 err
= __perf_evsel__name_array_test(perf_evsel__sw_names
,
107 PERF_COUNT_SW_DUMMY
+ 1);
111 err
= perf_evsel__roundtrip_cache_name_test();