Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / tools / perf / tests / builtin-test.c
blob6f8b01bc60330c71722e4d22a7d40b83c32fac25
1 /*
2 * builtin-test.c
4 * Builtin regression testing command: ever growing number of sanity tests
5 */
6 #include <unistd.h>
7 #include <string.h>
8 #include "builtin.h"
9 #include "intlist.h"
10 #include "tests.h"
11 #include "debug.h"
12 #include "color.h"
13 #include "parse-options.h"
14 #include "symbol.h"
16 static struct test {
17 const char *desc;
18 int (*func)(void);
19 } tests[] = {
21 .desc = "vmlinux symtab matches kallsyms",
22 .func = test__vmlinux_matches_kallsyms,
25 .desc = "detect open syscall event",
26 .func = test__open_syscall_event,
29 .desc = "detect open syscall event on all cpus",
30 .func = test__open_syscall_event_on_all_cpus,
33 .desc = "read samples using the mmap interface",
34 .func = test__basic_mmap,
37 .desc = "parse events tests",
38 .func = test__parse_events,
40 #if defined(__x86_64__) || defined(__i386__)
42 .desc = "x86 rdpmc test",
43 .func = test__rdpmc,
45 #endif
47 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
48 .func = test__PERF_RECORD,
51 .desc = "Test perf pmu format parsing",
52 .func = test__pmu,
55 .desc = "Test dso data read",
56 .func = test__dso_data,
59 .desc = "Test dso data cache",
60 .func = test__dso_data_cache,
63 .desc = "Test dso data reopen",
64 .func = test__dso_data_reopen,
67 .desc = "roundtrip evsel->name check",
68 .func = test__perf_evsel__roundtrip_name_test,
71 .desc = "Check parsing of sched tracepoints fields",
72 .func = test__perf_evsel__tp_sched_test,
75 .desc = "Generate and check syscalls:sys_enter_open event fields",
76 .func = test__syscall_open_tp_fields,
79 .desc = "struct perf_event_attr setup",
80 .func = test__attr,
83 .desc = "Test matching and linking multiple hists",
84 .func = test__hists_link,
87 .desc = "Try 'use perf' in python, checking link problems",
88 .func = test__python_use,
91 .desc = "Test breakpoint overflow signal handler",
92 .func = test__bp_signal,
95 .desc = "Test breakpoint overflow sampling",
96 .func = test__bp_signal_overflow,
99 .desc = "Test number of exit event of a simple workload",
100 .func = test__task_exit,
103 .desc = "Test software clock events have valid period values",
104 .func = test__sw_clock_freq,
106 #if defined(__x86_64__) || defined(__i386__)
108 .desc = "Test converting perf time to TSC",
109 .func = test__perf_time_to_tsc,
111 #endif
113 .desc = "Test object code reading",
114 .func = test__code_reading,
117 .desc = "Test sample parsing",
118 .func = test__sample_parsing,
121 .desc = "Test using a dummy software event to keep tracking",
122 .func = test__keep_tracking,
125 .desc = "Test parsing with no sample_id_all bit set",
126 .func = test__parse_no_sample_id_all,
128 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
129 #ifdef HAVE_DWARF_UNWIND_SUPPORT
131 .desc = "Test dwarf unwind",
132 .func = test__dwarf_unwind,
134 #endif
135 #endif
137 .desc = "Test filtering hist entries",
138 .func = test__hists_filter,
141 .desc = "Test mmap thread lookup",
142 .func = test__mmap_thread_lookup,
145 .desc = "Test thread mg sharing",
146 .func = test__thread_mg_share,
149 .desc = "Test output sorting of hist entries",
150 .func = test__hists_output,
153 .desc = "Test cumulation of child hist entries",
154 .func = test__hists_cumulate,
157 .func = NULL,
161 static bool perf_test__matches(int curr, int argc, const char *argv[])
163 int i;
165 if (argc == 0)
166 return true;
168 for (i = 0; i < argc; ++i) {
169 char *end;
170 long nr = strtoul(argv[i], &end, 10);
172 if (*end == '\0') {
173 if (nr == curr + 1)
174 return true;
175 continue;
178 if (strstr(tests[curr].desc, argv[i]))
179 return true;
182 return false;
185 static int run_test(struct test *test)
187 int status, err = -1, child = fork();
189 if (child < 0) {
190 pr_err("failed to fork test: %s\n", strerror(errno));
191 return -1;
194 if (!child) {
195 pr_debug("test child forked, pid %d\n", getpid());
196 err = test->func();
197 exit(err);
200 wait(&status);
202 if (WIFEXITED(status)) {
203 err = WEXITSTATUS(status);
204 pr_debug("test child finished with %d\n", err);
205 } else if (WIFSIGNALED(status)) {
206 err = -1;
207 pr_debug("test child interrupted\n");
210 return err;
213 static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
215 int i = 0;
216 int width = 0;
218 while (tests[i].func) {
219 int len = strlen(tests[i].desc);
221 if (width < len)
222 width = len;
223 ++i;
226 i = 0;
227 while (tests[i].func) {
228 int curr = i++, err;
230 if (!perf_test__matches(curr, argc, argv))
231 continue;
233 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
235 if (intlist__find(skiplist, i)) {
236 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
237 continue;
240 pr_debug("\n--- start ---\n");
241 err = run_test(&tests[curr]);
242 pr_debug("---- end ----\n%s:", tests[curr].desc);
244 switch (err) {
245 case TEST_OK:
246 pr_info(" Ok\n");
247 break;
248 case TEST_SKIP:
249 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
250 break;
251 case TEST_FAIL:
252 default:
253 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
254 break;
258 return 0;
261 static int perf_test__list(int argc, const char **argv)
263 int i = 0;
265 while (tests[i].func) {
266 int curr = i++;
268 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
269 continue;
271 pr_info("%2d: %s\n", i, tests[curr].desc);
274 return 0;
277 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
279 const char * const test_usage[] = {
280 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
281 NULL,
283 const char *skip = NULL;
284 const struct option test_options[] = {
285 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
286 OPT_INCR('v', "verbose", &verbose,
287 "be more verbose (show symbol address, etc)"),
288 OPT_END()
290 struct intlist *skiplist = NULL;
292 argc = parse_options(argc, argv, test_options, test_usage, 0);
293 if (argc >= 1 && !strcmp(argv[0], "list"))
294 return perf_test__list(argc, argv);
296 symbol_conf.priv_size = sizeof(int);
297 symbol_conf.sort_by_name = true;
298 symbol_conf.try_vmlinux_path = true;
300 if (symbol__init() < 0)
301 return -1;
303 if (skip != NULL)
304 skiplist = intlist__new(skip);
306 return __cmd_test(argc, argv, skiplist);