3 #include "parse-events.h"
6 static int perf_evsel__roundtrip_cache_name_test(void)
9 int type
, op
, err
= 0, ret
= 0, i
, idx
;
10 struct perf_evsel
*evsel
;
11 struct perf_evlist
*evlist
= perf_evlist__new();
16 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
17 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
18 /* skip invalid cache type */
19 if (!perf_evsel__is_cache_op_valid(type
, op
))
22 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
23 __perf_evsel__hw_cache_type_op_res_name(type
, op
, i
,
25 err
= parse_events(evlist
, name
);
33 evsel
= perf_evlist__first(evlist
);
35 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
36 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
37 /* skip invalid cache type */
38 if (!perf_evsel__is_cache_op_valid(type
, op
))
41 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
42 __perf_evsel__hw_cache_type_op_res_name(type
, op
, i
,
44 if (evsel
->idx
!= idx
)
49 if (strcmp(perf_evsel__name(evsel
), name
)) {
50 pr_debug("%s != %s\n", perf_evsel__name(evsel
), name
);
54 evsel
= perf_evsel__next(evsel
);
59 perf_evlist__delete(evlist
);
63 static int __perf_evsel__name_array_test(const char *names
[], int nr_names
)
66 struct perf_evsel
*evsel
;
67 struct perf_evlist
*evlist
= perf_evlist__new();
72 for (i
= 0; i
< nr_names
; ++i
) {
73 err
= parse_events(evlist
, names
[i
]);
75 pr_debug("failed to parse event '%s', err %d\n",
77 goto out_delete_evlist
;
82 evlist__for_each(evlist
, evsel
) {
83 if (strcmp(perf_evsel__name(evsel
), names
[evsel
->idx
])) {
85 pr_debug("%s != %s\n", perf_evsel__name(evsel
), names
[evsel
->idx
]);
90 perf_evlist__delete(evlist
);
94 #define perf_evsel__name_array_test(names) \
95 __perf_evsel__name_array_test(names, ARRAY_SIZE(names))
97 int test__perf_evsel__roundtrip_name_test(void)
101 err
= perf_evsel__name_array_test(perf_evsel__hw_names
);
105 err
= perf_evsel__name_array_test(perf_evsel__sw_names
);
109 err
= perf_evsel__roundtrip_cache_name_test();