Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / tools / perf / tests / evsel-roundtrip-name.c
blob2de4a4f2c3ed3df38e85e69f19dc68fc14f66f3d
1 #include "evlist.h"
2 #include "evsel.h"
3 #include "parse-events.h"
4 #include "tests.h"
5 #include "debug.h"
7 static int perf_evsel__roundtrip_cache_name_test(void)
9 char name[128];
10 int type, op, err = 0, ret = 0, i, idx;
11 struct perf_evsel *evsel;
12 struct perf_evlist *evlist = perf_evlist__new();
14 if (evlist == NULL)
15 return -ENOMEM;
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))
21 continue;
23 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
24 __perf_evsel__hw_cache_type_op_res_name(type, op, i,
25 name, sizeof(name));
26 err = parse_events(evlist, name, NULL);
27 if (err)
28 ret = err;
33 idx = 0;
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))
40 continue;
42 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
43 __perf_evsel__hw_cache_type_op_res_name(type, op, i,
44 name, sizeof(name));
45 if (evsel->idx != idx)
46 continue;
48 ++idx;
50 if (strcmp(perf_evsel__name(evsel), name)) {
51 pr_debug("%s != %s\n", perf_evsel__name(evsel), name);
52 ret = -1;
55 evsel = perf_evsel__next(evsel);
60 perf_evlist__delete(evlist);
61 return ret;
64 static int __perf_evsel__name_array_test(const char *names[], int nr_names)
66 int i, err;
67 struct perf_evsel *evsel;
68 struct perf_evlist *evlist = perf_evlist__new();
70 if (evlist == NULL)
71 return -ENOMEM;
73 for (i = 0; i < nr_names; ++i) {
74 err = parse_events(evlist, names[i], NULL);
75 if (err) {
76 pr_debug("failed to parse event '%s', err %d\n",
77 names[i], err);
78 goto out_delete_evlist;
82 err = 0;
83 evlist__for_each(evlist, evsel) {
84 if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
85 --err;
86 pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);
90 out_delete_evlist:
91 perf_evlist__delete(evlist);
92 return err;
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);
103 if (err)
104 ret = err;
106 err = __perf_evsel__name_array_test(perf_evsel__sw_names,
107 PERF_COUNT_SW_DUMMY + 1);
108 if (err)
109 ret = err;
111 err = perf_evsel__roundtrip_cache_name_test();
112 if (err)
113 ret = err;
115 return ret;