fix a kmap leak in virtio_console
[linux/fpc-iii.git] / tools / perf / tests / evsel-roundtrip-name.c
blob465cdbc345cf935d4abc7ea5bb465937659c3929
1 #include "evlist.h"
2 #include "evsel.h"
3 #include "parse-events.h"
4 #include "tests.h"
6 static int perf_evsel__roundtrip_cache_name_test(void)
8 char name[128];
9 int type, op, err = 0, ret = 0, i, idx;
10 struct perf_evsel *evsel;
11 struct perf_evlist *evlist = perf_evlist__new();
13 if (evlist == NULL)
14 return -ENOMEM;
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))
20 continue;
22 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
23 __perf_evsel__hw_cache_type_op_res_name(type, op, i,
24 name, sizeof(name));
25 err = parse_events(evlist, name);
26 if (err)
27 ret = err;
32 idx = 0;
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))
39 continue;
41 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
42 __perf_evsel__hw_cache_type_op_res_name(type, op, i,
43 name, sizeof(name));
44 if (evsel->idx != idx)
45 continue;
47 ++idx;
49 if (strcmp(perf_evsel__name(evsel), name)) {
50 pr_debug("%s != %s\n", perf_evsel__name(evsel), name);
51 ret = -1;
54 evsel = perf_evsel__next(evsel);
59 perf_evlist__delete(evlist);
60 return ret;
63 static int __perf_evsel__name_array_test(const char *names[], int nr_names)
65 int i, err;
66 struct perf_evsel *evsel;
67 struct perf_evlist *evlist = perf_evlist__new();
69 if (evlist == NULL)
70 return -ENOMEM;
72 for (i = 0; i < nr_names; ++i) {
73 err = parse_events(evlist, names[i]);
74 if (err) {
75 pr_debug("failed to parse event '%s', err %d\n",
76 names[i], err);
77 goto out_delete_evlist;
81 err = 0;
82 evlist__for_each(evlist, evsel) {
83 if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
84 --err;
85 pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);
89 out_delete_evlist:
90 perf_evlist__delete(evlist);
91 return err;
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)
99 int err = 0, ret = 0;
101 err = perf_evsel__name_array_test(perf_evsel__hw_names);
102 if (err)
103 ret = err;
105 err = perf_evsel__name_array_test(perf_evsel__sw_names);
106 if (err)
107 ret = err;
109 err = perf_evsel__roundtrip_cache_name_test();
110 if (err)
111 ret = err;
113 return ret;