Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 1 | #include "evlist.h" |
| 2 | #include "evsel.h" |
| 3 | #include "parse-events.h" |
| 4 | #include "tests.h" |
Jiri Olsa | 84f5d36 | 2014-07-14 23:46:48 +0200 | [diff] [blame] | 5 | #include "debug.h" |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 6 | |
| 7 | static int perf_evsel__roundtrip_cache_name_test(void) |
| 8 | { |
| 9 | char name[128]; |
| 10 | int type, op, err = 0, ret = 0, i, idx; |
| 11 | struct perf_evsel *evsel; |
Namhyung Kim | 334fe7a | 2013-03-11 16:43:12 +0900 | [diff] [blame] | 12 | struct perf_evlist *evlist = perf_evlist__new(); |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 13 | |
| 14 | if (evlist == NULL) |
| 15 | return -ENOMEM; |
| 16 | |
| 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; |
| 22 | |
| 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)); |
Jiri Olsa | d8f7bbc | 2013-01-15 14:39:51 +0100 | [diff] [blame] | 26 | err = parse_events(evlist, name); |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 27 | if (err) |
| 28 | ret = err; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | idx = 0; |
| 34 | evsel = perf_evlist__first(evlist); |
| 35 | |
| 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; |
| 41 | |
| 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; |
| 47 | |
| 48 | ++idx; |
| 49 | |
| 50 | if (strcmp(perf_evsel__name(evsel), name)) { |
| 51 | pr_debug("%s != %s\n", perf_evsel__name(evsel), name); |
| 52 | ret = -1; |
| 53 | } |
| 54 | |
| 55 | evsel = perf_evsel__next(evsel); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | perf_evlist__delete(evlist); |
| 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | static int __perf_evsel__name_array_test(const char *names[], int nr_names) |
| 65 | { |
| 66 | int i, err; |
| 67 | struct perf_evsel *evsel; |
Namhyung Kim | 334fe7a | 2013-03-11 16:43:12 +0900 | [diff] [blame] | 68 | struct perf_evlist *evlist = perf_evlist__new(); |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 69 | |
| 70 | if (evlist == NULL) |
| 71 | return -ENOMEM; |
| 72 | |
| 73 | for (i = 0; i < nr_names; ++i) { |
Jiri Olsa | d8f7bbc | 2013-01-15 14:39:51 +0100 | [diff] [blame] | 74 | err = parse_events(evlist, names[i]); |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 75 | if (err) { |
| 76 | pr_debug("failed to parse event '%s', err %d\n", |
| 77 | names[i], err); |
| 78 | goto out_delete_evlist; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | err = 0; |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 83 | evlist__for_each(evlist, evsel) { |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 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]); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | out_delete_evlist: |
| 91 | perf_evlist__delete(evlist); |
| 92 | return err; |
| 93 | } |
| 94 | |
| 95 | #define perf_evsel__name_array_test(names) \ |
| 96 | __perf_evsel__name_array_test(names, ARRAY_SIZE(names)) |
| 97 | |
| 98 | int test__perf_evsel__roundtrip_name_test(void) |
| 99 | { |
| 100 | int err = 0, ret = 0; |
| 101 | |
| 102 | err = perf_evsel__name_array_test(perf_evsel__hw_names); |
| 103 | if (err) |
| 104 | ret = err; |
| 105 | |
| 106 | err = perf_evsel__name_array_test(perf_evsel__sw_names); |
| 107 | if (err) |
| 108 | ret = err; |
| 109 | |
| 110 | err = perf_evsel__roundtrip_cache_name_test(); |
| 111 | if (err) |
| 112 | ret = err; |
| 113 | |
| 114 | return ret; |
| 115 | } |