blob: d3b95e04b7a3e6918b6798ff6760e73562b01a97 [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"
7
8#include "util/cache.h"
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -02009#include "util/color.h"
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030010#include "util/debug.h"
Arnaldo Carvalho de Meloebf294b2011-11-16 14:03:07 -020011#include "util/debugfs.h"
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020012#include "util/evlist.h"
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030013#include "util/machine.h"
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030014#include "util/parse-options.h"
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020015#include "util/parse-events.h"
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030016#include "util/symbol.h"
Arnaldo Carvalho de Melofd782602011-01-18 15:15:24 -020017#include "util/thread_map.h"
Jiri Olsacd82a322012-03-15 20:09:17 +010018#include "util/pmu.h"
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030019#include "event-parse.h"
Jiri Olsa13b62562011-07-14 11:25:33 +020020#include "../../include/linux/hw_breakpoint.h"
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030021
Peter Zijlstra08aa0d12011-11-21 14:42:47 +010022#include <sys/mman.h>
23
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020024#include "util/cpumap.h"
Arnaldo Carvalho de Melod8548612011-01-04 00:16:20 -020025#include "util/evsel.h"
26#include <sys/types.h>
27
Jiri Olsa0a4e1ae2012-11-10 01:46:41 +010028#include "tests.h"
29
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020030#include <sched.h>
31
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020032
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030033static struct test {
34 const char *desc;
35 int (*func)(void);
36} tests[] = {
37 {
38 .desc = "vmlinux symtab matches kallsyms",
39 .func = test__vmlinux_matches_kallsyms,
40 },
41 {
Arnaldo Carvalho de Melod8548612011-01-04 00:16:20 -020042 .desc = "detect open syscall event",
43 .func = test__open_syscall_event,
44 },
45 {
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020046 .desc = "detect open syscall event on all cpus",
47 .func = test__open_syscall_event_on_all_cpus,
48 },
49 {
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020050 .desc = "read samples using the mmap interface",
51 .func = test__basic_mmap,
52 },
53 {
Jiri Olsa13b62562011-07-14 11:25:33 +020054 .desc = "parse events tests",
Jiri Olsaf50246e2012-05-21 09:12:49 +020055 .func = parse_events__test,
Jiri Olsa13b62562011-07-14 11:25:33 +020056 },
Peter Zijlstra08aa0d12011-11-21 14:42:47 +010057#if defined(__x86_64__) || defined(__i386__)
58 {
59 .desc = "x86 rdpmc test",
60 .func = test__rdpmc,
61 },
62#endif
Jiri Olsa13b62562011-07-14 11:25:33 +020063 {
Arnaldo Carvalho de Melo3e7c4392011-12-02 11:13:50 -020064 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
65 .func = test__PERF_RECORD,
66 },
67 {
Jiri Olsacd82a322012-03-15 20:09:17 +010068 .desc = "Test perf pmu format parsing",
Jiri Olsacff7f952012-11-10 01:46:50 +010069 .func = test__pmu,
Jiri Olsacd82a322012-03-15 20:09:17 +010070 },
71 {
Jiri Olsaf7add552012-07-22 14:14:40 +020072 .desc = "Test dso data interface",
73 .func = dso__test_data,
74 },
75 {
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030076 .desc = "roundtrip evsel->name check",
Jiri Olsacfffae22012-11-10 01:46:47 +010077 .func = test__perf_evsel__roundtrip_name_test,
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030078 },
79 {
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030080 .desc = "Check parsing of sched tracepoints fields",
Jiri Olsa5e24a092012-11-10 01:46:48 +010081 .func = test__perf_evsel__tp_sched_test,
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030082 },
83 {
Arnaldo Carvalho de Meloeb2f2702012-09-26 13:23:10 -030084 .desc = "Generate and check syscalls:sys_enter_open event fields",
85 .func = test__syscall_open_tp_fields,
86 },
87 {
Jiri Olsad898b242012-10-30 23:02:05 +010088 .desc = "struct perf_event_attr setup",
89 .func = test_attr__run,
90 },
91 {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030092 .func = NULL,
93 },
94};
95
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -020096static bool perf_test__matches(int curr, int argc, const char *argv[])
97{
98 int i;
99
100 if (argc == 0)
101 return true;
102
103 for (i = 0; i < argc; ++i) {
104 char *end;
105 long nr = strtoul(argv[i], &end, 10);
106
107 if (*end == '\0') {
108 if (nr == curr + 1)
109 return true;
110 continue;
111 }
112
113 if (strstr(tests[curr].desc, argv[i]))
114 return true;
115 }
116
117 return false;
118}
119
120static int __cmd_test(int argc, const char *argv[])
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300121{
122 int i = 0;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200123 int width = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300124
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300125 while (tests[i].func) {
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200126 int len = strlen(tests[i].desc);
127
128 if (width < len)
129 width = len;
130 ++i;
131 }
Jiri Olsa945aea22012-10-30 23:01:43 +0100132
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200133 i = 0;
134 while (tests[i].func) {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200135 int curr = i++, err;
136
137 if (!perf_test__matches(curr, argc, argv))
138 continue;
139
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200140 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300141 pr_debug("\n--- start ---\n");
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200142 err = tests[curr].func();
143 pr_debug("---- end ----\n%s:", tests[curr].desc);
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200144 if (err)
145 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
146 else
147 pr_info(" Ok\n");
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300148 }
149
150 return 0;
151}
152
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200153static int perf_test__list(int argc, const char **argv)
154{
155 int i = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300156
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200157 while (tests[i].func) {
158 int curr = i++;
159
160 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
161 continue;
162
163 pr_info("%2d: %s\n", i, tests[curr].desc);
164 }
165
166 return 0;
167}
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300168
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300169int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300170{
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200171 const char * const test_usage[] = {
172 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
173 NULL,
174 };
175 const struct option test_options[] = {
Namhyung Kimc30ab8a2012-01-08 02:25:26 +0900176 OPT_INCR('v', "verbose", &verbose,
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200177 "be more verbose (show symbol address, etc)"),
178 OPT_END()
179 };
180
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300181 argc = parse_options(argc, argv, test_options, test_usage, 0);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200182 if (argc >= 1 && !strcmp(argv[0], "list"))
183 return perf_test__list(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300184
185 symbol_conf.priv_size = sizeof(int);
186 symbol_conf.sort_by_name = true;
187 symbol_conf.try_vmlinux_path = true;
188
189 if (symbol__init() < 0)
190 return -1;
191
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200192 return __cmd_test(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300193}