perf tests: Move test__syscall_open_tp_fields into separate object
[linux-2.6.git] / tools / perf / tests / builtin-test.c
blobbab849039852310490a6e37bdc8bcfd072c49fc2
1 /*
2 * builtin-test.c
4 * Builtin regression testing command: ever growing number of sanity tests
5 */
6 #include "builtin.h"
8 #include "util/cache.h"
9 #include "util/color.h"
10 #include "util/debug.h"
11 #include "util/debugfs.h"
12 #include "util/evlist.h"
13 #include "util/machine.h"
14 #include "util/parse-options.h"
15 #include "util/parse-events.h"
16 #include "util/symbol.h"
17 #include "util/thread_map.h"
18 #include "util/pmu.h"
19 #include "event-parse.h"
20 #include "../../include/linux/hw_breakpoint.h"
22 #include <sys/mman.h>
24 #include "util/cpumap.h"
25 #include "util/evsel.h"
26 #include <sys/types.h>
28 #include "tests.h"
30 #include <sched.h>
33 static int test__perf_pmu(void)
35 return perf_pmu__test();
38 static struct test {
39 const char *desc;
40 int (*func)(void);
41 } tests[] = {
43 .desc = "vmlinux symtab matches kallsyms",
44 .func = test__vmlinux_matches_kallsyms,
47 .desc = "detect open syscall event",
48 .func = test__open_syscall_event,
51 .desc = "detect open syscall event on all cpus",
52 .func = test__open_syscall_event_on_all_cpus,
55 .desc = "read samples using the mmap interface",
56 .func = test__basic_mmap,
59 .desc = "parse events tests",
60 .func = parse_events__test,
62 #if defined(__x86_64__) || defined(__i386__)
64 .desc = "x86 rdpmc test",
65 .func = test__rdpmc,
67 #endif
69 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
70 .func = test__PERF_RECORD,
73 .desc = "Test perf pmu format parsing",
74 .func = test__perf_pmu,
77 .desc = "Test dso data interface",
78 .func = dso__test_data,
81 .desc = "roundtrip evsel->name check",
82 .func = test__perf_evsel__roundtrip_name_test,
85 .desc = "Check parsing of sched tracepoints fields",
86 .func = test__perf_evsel__tp_sched_test,
89 .desc = "Generate and check syscalls:sys_enter_open event fields",
90 .func = test__syscall_open_tp_fields,
93 .desc = "struct perf_event_attr setup",
94 .func = test_attr__run,
97 .func = NULL,
101 static bool perf_test__matches(int curr, int argc, const char *argv[])
103 int i;
105 if (argc == 0)
106 return true;
108 for (i = 0; i < argc; ++i) {
109 char *end;
110 long nr = strtoul(argv[i], &end, 10);
112 if (*end == '\0') {
113 if (nr == curr + 1)
114 return true;
115 continue;
118 if (strstr(tests[curr].desc, argv[i]))
119 return true;
122 return false;
125 static int __cmd_test(int argc, const char *argv[])
127 int i = 0;
128 int width = 0;
130 while (tests[i].func) {
131 int len = strlen(tests[i].desc);
133 if (width < len)
134 width = len;
135 ++i;
138 i = 0;
139 while (tests[i].func) {
140 int curr = i++, err;
142 if (!perf_test__matches(curr, argc, argv))
143 continue;
145 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
146 pr_debug("\n--- start ---\n");
147 err = tests[curr].func();
148 pr_debug("---- end ----\n%s:", tests[curr].desc);
149 if (err)
150 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
151 else
152 pr_info(" Ok\n");
155 return 0;
158 static int perf_test__list(int argc, const char **argv)
160 int i = 0;
162 while (tests[i].func) {
163 int curr = i++;
165 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
166 continue;
168 pr_info("%2d: %s\n", i, tests[curr].desc);
171 return 0;
174 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
176 const char * const test_usage[] = {
177 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
178 NULL,
180 const struct option test_options[] = {
181 OPT_INCR('v', "verbose", &verbose,
182 "be more verbose (show symbol address, etc)"),
183 OPT_END()
186 argc = parse_options(argc, argv, test_options, test_usage, 0);
187 if (argc >= 1 && !strcmp(argv[0], "list"))
188 return perf_test__list(argc, argv);
190 symbol_conf.priv_size = sizeof(int);
191 symbol_conf.sort_by_name = true;
192 symbol_conf.try_vmlinux_path = true;
194 if (symbol__init() < 0)
195 return -1;
197 return __cmd_test(argc, argv);