diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-11-09 19:46:47 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-11-14 14:49:56 -0500 |
commit | cfffae2ef7029d38e71d337fbc2a9c6cf1fa5aaf (patch) | |
tree | 1840c55218621ab65ba099919af1f1268fd6e4a5 /tools | |
parent | bacf7e5d4055b65506292cf6412ec71e7948a9cf (diff) |
perf tests: Move perf_evsel__roundtrip_name_test into separate object
Separating perf_evsel__roundtrip_name_test test from the builtin-test
into evsel-roundtrip-name object.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1352508412-16914-8-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/Makefile | 1 | ||||
-rw-r--r-- | tools/perf/tests/builtin-test.c | 112 | ||||
-rw-r--r-- | tools/perf/tests/evsel-roundtrip-name.c | 114 | ||||
-rw-r--r-- | tools/perf/tests/tests.h | 1 |
4 files changed, 117 insertions, 111 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 2e5197a0ad6e..ad6fcb5f582c 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -437,6 +437,7 @@ LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o | |||
437 | LIB_OBJS += $(OUTPUT)tests/mmap-basic.o | 437 | LIB_OBJS += $(OUTPUT)tests/mmap-basic.o |
438 | LIB_OBJS += $(OUTPUT)tests/perf-record.o | 438 | LIB_OBJS += $(OUTPUT)tests/perf-record.o |
439 | LIB_OBJS += $(OUTPUT)tests/rdpmc.o | 439 | LIB_OBJS += $(OUTPUT)tests/rdpmc.o |
440 | LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o | ||
440 | LIB_OBJS += $(OUTPUT)tests/util.o | 441 | LIB_OBJS += $(OUTPUT)tests/util.o |
441 | 442 | ||
442 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o | 443 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 1e9a0ea68fb2..93f5e9176e68 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
@@ -35,116 +35,6 @@ static int test__perf_pmu(void) | |||
35 | return perf_pmu__test(); | 35 | return perf_pmu__test(); |
36 | } | 36 | } |
37 | 37 | ||
38 | static int perf_evsel__roundtrip_cache_name_test(void) | ||
39 | { | ||
40 | char name[128]; | ||
41 | int type, op, err = 0, ret = 0, i, idx; | ||
42 | struct perf_evsel *evsel; | ||
43 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | ||
44 | |||
45 | if (evlist == NULL) | ||
46 | return -ENOMEM; | ||
47 | |||
48 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { | ||
49 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { | ||
50 | /* skip invalid cache type */ | ||
51 | if (!perf_evsel__is_cache_op_valid(type, op)) | ||
52 | continue; | ||
53 | |||
54 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { | ||
55 | __perf_evsel__hw_cache_type_op_res_name(type, op, i, | ||
56 | name, sizeof(name)); | ||
57 | err = parse_events(evlist, name, 0); | ||
58 | if (err) | ||
59 | ret = err; | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | idx = 0; | ||
65 | evsel = perf_evlist__first(evlist); | ||
66 | |||
67 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { | ||
68 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { | ||
69 | /* skip invalid cache type */ | ||
70 | if (!perf_evsel__is_cache_op_valid(type, op)) | ||
71 | continue; | ||
72 | |||
73 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { | ||
74 | __perf_evsel__hw_cache_type_op_res_name(type, op, i, | ||
75 | name, sizeof(name)); | ||
76 | if (evsel->idx != idx) | ||
77 | continue; | ||
78 | |||
79 | ++idx; | ||
80 | |||
81 | if (strcmp(perf_evsel__name(evsel), name)) { | ||
82 | pr_debug("%s != %s\n", perf_evsel__name(evsel), name); | ||
83 | ret = -1; | ||
84 | } | ||
85 | |||
86 | evsel = perf_evsel__next(evsel); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | perf_evlist__delete(evlist); | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | static int __perf_evsel__name_array_test(const char *names[], int nr_names) | ||
96 | { | ||
97 | int i, err; | ||
98 | struct perf_evsel *evsel; | ||
99 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | ||
100 | |||
101 | if (evlist == NULL) | ||
102 | return -ENOMEM; | ||
103 | |||
104 | for (i = 0; i < nr_names; ++i) { | ||
105 | err = parse_events(evlist, names[i], 0); | ||
106 | if (err) { | ||
107 | pr_debug("failed to parse event '%s', err %d\n", | ||
108 | names[i], err); | ||
109 | goto out_delete_evlist; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | err = 0; | ||
114 | list_for_each_entry(evsel, &evlist->entries, node) { | ||
115 | if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) { | ||
116 | --err; | ||
117 | pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | out_delete_evlist: | ||
122 | perf_evlist__delete(evlist); | ||
123 | return err; | ||
124 | } | ||
125 | |||
126 | #define perf_evsel__name_array_test(names) \ | ||
127 | __perf_evsel__name_array_test(names, ARRAY_SIZE(names)) | ||
128 | |||
129 | static int perf_evsel__roundtrip_name_test(void) | ||
130 | { | ||
131 | int err = 0, ret = 0; | ||
132 | |||
133 | err = perf_evsel__name_array_test(perf_evsel__hw_names); | ||
134 | if (err) | ||
135 | ret = err; | ||
136 | |||
137 | err = perf_evsel__name_array_test(perf_evsel__sw_names); | ||
138 | if (err) | ||
139 | ret = err; | ||
140 | |||
141 | err = perf_evsel__roundtrip_cache_name_test(); | ||
142 | if (err) | ||
143 | ret = err; | ||
144 | |||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, | 38 | static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, |
149 | int size, bool should_be_signed) | 39 | int size, bool should_be_signed) |
150 | { | 40 | { |
@@ -382,7 +272,7 @@ static struct test { | |||
382 | }, | 272 | }, |
383 | { | 273 | { |
384 | .desc = "roundtrip evsel->name check", | 274 | .desc = "roundtrip evsel->name check", |
385 | .func = perf_evsel__roundtrip_name_test, | 275 | .func = test__perf_evsel__roundtrip_name_test, |
386 | }, | 276 | }, |
387 | { | 277 | { |
388 | .desc = "Check parsing of sched tracepoints fields", | 278 | .desc = "Check parsing of sched tracepoints fields", |
diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c new file mode 100644 index 000000000000..e61fc828a158 --- /dev/null +++ b/tools/perf/tests/evsel-roundtrip-name.c | |||
@@ -0,0 +1,114 @@ | |||
1 | #include "evlist.h" | ||
2 | #include "evsel.h" | ||
3 | #include "parse-events.h" | ||
4 | #include "tests.h" | ||
5 | |||
6 | static int perf_evsel__roundtrip_cache_name_test(void) | ||
7 | { | ||
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(NULL, NULL); | ||
12 | |||
13 | if (evlist == NULL) | ||
14 | return -ENOMEM; | ||
15 | |||
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; | ||
21 | |||
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, 0); | ||
26 | if (err) | ||
27 | ret = err; | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | |||
32 | idx = 0; | ||
33 | evsel = perf_evlist__first(evlist); | ||
34 | |||
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; | ||
40 | |||
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; | ||
46 | |||
47 | ++idx; | ||
48 | |||
49 | if (strcmp(perf_evsel__name(evsel), name)) { | ||
50 | pr_debug("%s != %s\n", perf_evsel__name(evsel), name); | ||
51 | ret = -1; | ||
52 | } | ||
53 | |||
54 | evsel = perf_evsel__next(evsel); | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | |||
59 | perf_evlist__delete(evlist); | ||
60 | return ret; | ||
61 | } | ||
62 | |||
63 | static int __perf_evsel__name_array_test(const char *names[], int nr_names) | ||
64 | { | ||
65 | int i, err; | ||
66 | struct perf_evsel *evsel; | ||
67 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | ||
68 | |||
69 | if (evlist == NULL) | ||
70 | return -ENOMEM; | ||
71 | |||
72 | for (i = 0; i < nr_names; ++i) { | ||
73 | err = parse_events(evlist, names[i], 0); | ||
74 | if (err) { | ||
75 | pr_debug("failed to parse event '%s', err %d\n", | ||
76 | names[i], err); | ||
77 | goto out_delete_evlist; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | err = 0; | ||
82 | list_for_each_entry(evsel, &evlist->entries, node) { | ||
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]); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | out_delete_evlist: | ||
90 | perf_evlist__delete(evlist); | ||
91 | return err; | ||
92 | } | ||
93 | |||
94 | #define perf_evsel__name_array_test(names) \ | ||
95 | __perf_evsel__name_array_test(names, ARRAY_SIZE(names)) | ||
96 | |||
97 | int test__perf_evsel__roundtrip_name_test(void) | ||
98 | { | ||
99 | int err = 0, ret = 0; | ||
100 | |||
101 | err = perf_evsel__name_array_test(perf_evsel__hw_names); | ||
102 | if (err) | ||
103 | ret = err; | ||
104 | |||
105 | err = perf_evsel__name_array_test(perf_evsel__sw_names); | ||
106 | if (err) | ||
107 | ret = err; | ||
108 | |||
109 | err = perf_evsel__roundtrip_cache_name_test(); | ||
110 | if (err) | ||
111 | ret = err; | ||
112 | |||
113 | return ret; | ||
114 | } | ||
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 03d428d72432..5897dd13efa3 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
@@ -8,6 +8,7 @@ int test__open_syscall_event_on_all_cpus(void); | |||
8 | int test__basic_mmap(void); | 8 | int test__basic_mmap(void); |
9 | int test__PERF_RECORD(void); | 9 | int test__PERF_RECORD(void); |
10 | int test__rdpmc(void); | 10 | int test__rdpmc(void); |
11 | int test__perf_evsel__roundtrip_name_test(void); | ||
11 | 12 | ||
12 | /* Util */ | 13 | /* Util */ |
13 | int trace_event__id(const char *evname); | 14 | int trace_event__id(const char *evname); |