blob: 8bbeba322df9ea760f4a527821a1905cd0415bdc [file] [log] [blame]
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -03001/*
2 * builtin-test.c
3 *
4 * Builtin regression testing command: ever growing number of sanity tests
5 */
6#include "builtin.h"
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -03007#include "intlist.h"
Jiri Olsa0a4e1ae2012-11-10 01:46:41 +01008#include "tests.h"
Jiri Olsac81251e2012-11-10 01:46:51 +01009#include "debug.h"
10#include "color.h"
11#include "parse-options.h"
12#include "symbol.h"
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020013
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030014static struct test {
15 const char *desc;
16 int (*func)(void);
17} tests[] = {
18 {
19 .desc = "vmlinux symtab matches kallsyms",
20 .func = test__vmlinux_matches_kallsyms,
21 },
22 {
Arnaldo Carvalho de Melod8548612011-01-04 00:16:20 -020023 .desc = "detect open syscall event",
24 .func = test__open_syscall_event,
25 },
26 {
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020027 .desc = "detect open syscall event on all cpus",
28 .func = test__open_syscall_event_on_all_cpus,
29 },
30 {
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020031 .desc = "read samples using the mmap interface",
32 .func = test__basic_mmap,
33 },
34 {
Jiri Olsa13b62562011-07-14 11:25:33 +020035 .desc = "parse events tests",
Jiri Olsac81251e2012-11-10 01:46:51 +010036 .func = test__parse_events,
Jiri Olsa13b62562011-07-14 11:25:33 +020037 },
Peter Zijlstra08aa0d12011-11-21 14:42:47 +010038#if defined(__x86_64__) || defined(__i386__)
39 {
40 .desc = "x86 rdpmc test",
41 .func = test__rdpmc,
42 },
43#endif
Jiri Olsa13b62562011-07-14 11:25:33 +020044 {
Arnaldo Carvalho de Melo3e7c4392011-12-02 11:13:50 -020045 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
46 .func = test__PERF_RECORD,
47 },
48 {
Jiri Olsacd82a322012-03-15 20:09:17 +010049 .desc = "Test perf pmu format parsing",
Jiri Olsacff7f952012-11-10 01:46:50 +010050 .func = test__pmu,
Jiri Olsacd82a322012-03-15 20:09:17 +010051 },
52 {
Jiri Olsaf7add552012-07-22 14:14:40 +020053 .desc = "Test dso data interface",
Jiri Olsac81251e2012-11-10 01:46:51 +010054 .func = test__dso_data,
Jiri Olsaf7add552012-07-22 14:14:40 +020055 },
56 {
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030057 .desc = "roundtrip evsel->name check",
Jiri Olsacfffae22012-11-10 01:46:47 +010058 .func = test__perf_evsel__roundtrip_name_test,
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030059 },
60 {
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030061 .desc = "Check parsing of sched tracepoints fields",
Jiri Olsa5e24a092012-11-10 01:46:48 +010062 .func = test__perf_evsel__tp_sched_test,
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030063 },
64 {
Arnaldo Carvalho de Meloeb2f2702012-09-26 13:23:10 -030065 .desc = "Generate and check syscalls:sys_enter_open event fields",
66 .func = test__syscall_open_tp_fields,
67 },
68 {
Jiri Olsad898b242012-10-30 23:02:05 +010069 .desc = "struct perf_event_attr setup",
Jiri Olsac81251e2012-11-10 01:46:51 +010070 .func = test__attr,
Jiri Olsad898b242012-10-30 23:02:05 +010071 },
72 {
Arnaldo Carvalho de Meloffcbaa12013-05-23 12:08:38 +020073 .desc = "Test matching and linking multiple hists",
Namhyung Kimf8ebb0c2012-12-10 17:29:57 +090074 .func = test__hists_link,
75 },
76 {
Arnaldo Carvalho de Melo54359d32012-12-14 13:06:13 -030077 .desc = "Try 'use perf' in python, checking link problems",
78 .func = test__python_use,
79 },
80 {
Jiri Olsa5a6bef42013-03-10 19:41:10 +010081 .desc = "Test breakpoint overflow signal handler",
82 .func = test__bp_signal,
83 },
84 {
Jiri Olsa06933e32013-03-10 19:41:11 +010085 .desc = "Test breakpoint overflow sampling",
86 .func = test__bp_signal_overflow,
87 },
88 {
Namhyung Kimd723a552013-03-15 14:58:11 +090089 .desc = "Test number of exit event of a simple workload",
90 .func = test__task_exit,
91 },
92 {
Namhyung Kimbc96b362013-03-18 11:41:47 +090093 .desc = "Test software clock events have valid period values",
94 .func = test__sw_clock_freq,
95 },
Adrian Hunter3bd5a5f2013-06-28 16:22:19 +030096#if defined(__x86_64__) || defined(__i386__)
97 {
98 .desc = "Test converting perf time to TSC",
99 .func = test__perf_time_to_tsc,
100 },
101#endif
Namhyung Kimbc96b362013-03-18 11:41:47 +0900102 {
Adrian Hunterb55ae0a2013-08-07 14:38:45 +0300103 .desc = "Test object code reading",
104 .func = test__code_reading,
105 },
106 {
Adrian Hunter045f8cd82013-08-27 11:23:13 +0300107 .desc = "Test sample parsing",
108 .func = test__sample_parsing,
109 },
110 {
Adrian Hunter395c3072013-08-31 21:50:53 +0300111 .desc = "Test using a dummy software event to keep tracking",
112 .func = test__keep_tracking,
113 },
114 {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300115 .func = NULL,
116 },
117};
118
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200119static bool perf_test__matches(int curr, int argc, const char *argv[])
120{
121 int i;
122
123 if (argc == 0)
124 return true;
125
126 for (i = 0; i < argc; ++i) {
127 char *end;
128 long nr = strtoul(argv[i], &end, 10);
129
130 if (*end == '\0') {
131 if (nr == curr + 1)
132 return true;
133 continue;
134 }
135
136 if (strstr(tests[curr].desc, argv[i]))
137 return true;
138 }
139
140 return false;
141}
142
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300143static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300144{
145 int i = 0;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200146 int width = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300147
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300148 while (tests[i].func) {
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200149 int len = strlen(tests[i].desc);
150
151 if (width < len)
152 width = len;
153 ++i;
154 }
Jiri Olsa945aea22012-10-30 23:01:43 +0100155
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200156 i = 0;
157 while (tests[i].func) {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200158 int curr = i++, err;
159
160 if (!perf_test__matches(curr, argc, argv))
161 continue;
162
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200163 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300164
165 if (intlist__find(skiplist, i)) {
166 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
167 continue;
168 }
169
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300170 pr_debug("\n--- start ---\n");
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200171 err = tests[curr].func();
172 pr_debug("---- end ----\n%s:", tests[curr].desc);
Jiri Olsaf4c1ea52012-12-19 11:33:39 -0300173
174 switch (err) {
175 case TEST_OK:
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200176 pr_info(" Ok\n");
Jiri Olsaf4c1ea52012-12-19 11:33:39 -0300177 break;
178 case TEST_SKIP:
179 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
180 break;
181 case TEST_FAIL:
182 default:
183 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
184 break;
185 }
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300186 }
187
188 return 0;
189}
190
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200191static int perf_test__list(int argc, const char **argv)
192{
193 int i = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300194
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200195 while (tests[i].func) {
196 int curr = i++;
197
198 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
199 continue;
200
201 pr_info("%2d: %s\n", i, tests[curr].desc);
202 }
203
204 return 0;
205}
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300206
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300207int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300208{
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200209 const char * const test_usage[] = {
210 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
211 NULL,
212 };
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300213 const char *skip = NULL;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200214 const struct option test_options[] = {
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300215 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
Namhyung Kimc30ab8a2012-01-08 02:25:26 +0900216 OPT_INCR('v', "verbose", &verbose,
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200217 "be more verbose (show symbol address, etc)"),
218 OPT_END()
219 };
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300220 struct intlist *skiplist = NULL;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200221
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300222 argc = parse_options(argc, argv, test_options, test_usage, 0);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200223 if (argc >= 1 && !strcmp(argv[0], "list"))
224 return perf_test__list(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300225
226 symbol_conf.priv_size = sizeof(int);
227 symbol_conf.sort_by_name = true;
228 symbol_conf.try_vmlinux_path = true;
229
230 if (symbol__init() < 0)
231 return -1;
232
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300233 if (skip != NULL)
234 skiplist = intlist__new(skip);
235
236 return __cmd_test(argc, argv, skiplist);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300237}