blob: 479d10484a7458ece9fabe83bc75fb2277bd3cd0 [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"
Jiri Olsa0a4e1ae2012-11-10 01:46:41 +01007#include "tests.h"
Jiri Olsac81251e2012-11-10 01:46:51 +01008#include "debug.h"
9#include "color.h"
10#include "parse-options.h"
11#include "symbol.h"
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020012
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030013static struct test {
14 const char *desc;
15 int (*func)(void);
16} tests[] = {
17 {
18 .desc = "vmlinux symtab matches kallsyms",
19 .func = test__vmlinux_matches_kallsyms,
20 },
21 {
Arnaldo Carvalho de Melod8548612011-01-04 00:16:20 -020022 .desc = "detect open syscall event",
23 .func = test__open_syscall_event,
24 },
25 {
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020026 .desc = "detect open syscall event on all cpus",
27 .func = test__open_syscall_event_on_all_cpus,
28 },
29 {
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020030 .desc = "read samples using the mmap interface",
31 .func = test__basic_mmap,
32 },
33 {
Jiri Olsa13b62562011-07-14 11:25:33 +020034 .desc = "parse events tests",
Jiri Olsac81251e2012-11-10 01:46:51 +010035 .func = test__parse_events,
Jiri Olsa13b62562011-07-14 11:25:33 +020036 },
Peter Zijlstra08aa0d12011-11-21 14:42:47 +010037#if defined(__x86_64__) || defined(__i386__)
38 {
39 .desc = "x86 rdpmc test",
40 .func = test__rdpmc,
41 },
42#endif
Jiri Olsa13b62562011-07-14 11:25:33 +020043 {
Arnaldo Carvalho de Melo3e7c4392011-12-02 11:13:50 -020044 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
45 .func = test__PERF_RECORD,
46 },
47 {
Jiri Olsacd82a322012-03-15 20:09:17 +010048 .desc = "Test perf pmu format parsing",
Jiri Olsacff7f952012-11-10 01:46:50 +010049 .func = test__pmu,
Jiri Olsacd82a322012-03-15 20:09:17 +010050 },
51 {
Jiri Olsaf7add552012-07-22 14:14:40 +020052 .desc = "Test dso data interface",
Jiri Olsac81251e2012-11-10 01:46:51 +010053 .func = test__dso_data,
Jiri Olsaf7add552012-07-22 14:14:40 +020054 },
55 {
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030056 .desc = "roundtrip evsel->name check",
Jiri Olsacfffae22012-11-10 01:46:47 +010057 .func = test__perf_evsel__roundtrip_name_test,
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030058 },
59 {
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030060 .desc = "Check parsing of sched tracepoints fields",
Jiri Olsa5e24a092012-11-10 01:46:48 +010061 .func = test__perf_evsel__tp_sched_test,
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030062 },
63 {
Arnaldo Carvalho de Meloeb2f2702012-09-26 13:23:10 -030064 .desc = "Generate and check syscalls:sys_enter_open event fields",
65 .func = test__syscall_open_tp_fields,
66 },
67 {
Jiri Olsad898b242012-10-30 23:02:05 +010068 .desc = "struct perf_event_attr setup",
Jiri Olsac81251e2012-11-10 01:46:51 +010069 .func = test__attr,
Jiri Olsad898b242012-10-30 23:02:05 +010070 },
71 {
Namhyung Kimf8ebb0c2012-12-10 17:29:57 +090072 .desc = "Test matching and linking mutliple hists",
73 .func = test__hists_link,
74 },
75 {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030076 .func = NULL,
77 },
78};
79
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -020080static bool perf_test__matches(int curr, int argc, const char *argv[])
81{
82 int i;
83
84 if (argc == 0)
85 return true;
86
87 for (i = 0; i < argc; ++i) {
88 char *end;
89 long nr = strtoul(argv[i], &end, 10);
90
91 if (*end == '\0') {
92 if (nr == curr + 1)
93 return true;
94 continue;
95 }
96
97 if (strstr(tests[curr].desc, argv[i]))
98 return true;
99 }
100
101 return false;
102}
103
104static int __cmd_test(int argc, const char *argv[])
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300105{
106 int i = 0;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200107 int width = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300108
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300109 while (tests[i].func) {
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200110 int len = strlen(tests[i].desc);
111
112 if (width < len)
113 width = len;
114 ++i;
115 }
Jiri Olsa945aea22012-10-30 23:01:43 +0100116
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200117 i = 0;
118 while (tests[i].func) {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200119 int curr = i++, err;
120
121 if (!perf_test__matches(curr, argc, argv))
122 continue;
123
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200124 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300125 pr_debug("\n--- start ---\n");
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200126 err = tests[curr].func();
127 pr_debug("---- end ----\n%s:", tests[curr].desc);
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200128 if (err)
129 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
130 else
131 pr_info(" Ok\n");
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300132 }
133
134 return 0;
135}
136
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200137static int perf_test__list(int argc, const char **argv)
138{
139 int i = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300140
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200141 while (tests[i].func) {
142 int curr = i++;
143
144 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
145 continue;
146
147 pr_info("%2d: %s\n", i, tests[curr].desc);
148 }
149
150 return 0;
151}
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300152
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300153int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300154{
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200155 const char * const test_usage[] = {
156 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
157 NULL,
158 };
159 const struct option test_options[] = {
Namhyung Kimc30ab8a2012-01-08 02:25:26 +0900160 OPT_INCR('v', "verbose", &verbose,
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200161 "be more verbose (show symbol address, etc)"),
162 OPT_END()
163 };
164
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300165 argc = parse_options(argc, argv, test_options, test_usage, 0);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200166 if (argc >= 1 && !strcmp(argv[0], "list"))
167 return perf_test__list(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300168
169 symbol_conf.priv_size = sizeof(int);
170 symbol_conf.sort_by_name = true;
171 symbol_conf.try_vmlinux_path = true;
172
173 if (symbol__init() < 0)
174 return -1;
175
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200176 return __cmd_test(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300177}