ARM: rockchip: fix broken build
[linux/fpc-iii.git] / tools / perf / tests / builtin-test.c
blobc1dde733c3a6b594ccab52a2a0077c3504c95fc2
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 "hist.h"
10 #include "intlist.h"
11 #include "tests.h"
12 #include "debug.h"
13 #include "color.h"
14 #include "parse-options.h"
15 #include "symbol.h"
17 static struct test {
18 const char *desc;
19 int (*func)(void);
20 } tests[] = {
22 .desc = "vmlinux symtab matches kallsyms",
23 .func = test__vmlinux_matches_kallsyms,
26 .desc = "detect openat syscall event",
27 .func = test__openat_syscall_event,
30 .desc = "detect openat syscall event on all cpus",
31 .func = test__openat_syscall_event_on_all_cpus,
34 .desc = "read samples using the mmap interface",
35 .func = test__basic_mmap,
38 .desc = "parse events tests",
39 .func = test__parse_events,
41 #if defined(__x86_64__) || defined(__i386__)
43 .desc = "x86 rdpmc test",
44 .func = test__rdpmc,
46 #endif
48 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
49 .func = test__PERF_RECORD,
52 .desc = "Test perf pmu format parsing",
53 .func = test__pmu,
56 .desc = "Test dso data read",
57 .func = test__dso_data,
60 .desc = "Test dso data cache",
61 .func = test__dso_data_cache,
64 .desc = "Test dso data reopen",
65 .func = test__dso_data_reopen,
68 .desc = "roundtrip evsel->name check",
69 .func = test__perf_evsel__roundtrip_name_test,
72 .desc = "Check parsing of sched tracepoints fields",
73 .func = test__perf_evsel__tp_sched_test,
76 .desc = "Generate and check syscalls:sys_enter_openat event fields",
77 .func = test__syscall_openat_tp_fields,
80 .desc = "struct perf_event_attr setup",
81 .func = test__attr,
84 .desc = "Test matching and linking multiple hists",
85 .func = test__hists_link,
88 .desc = "Try 'import perf' in python, checking link problems",
89 .func = test__python_use,
92 .desc = "Test breakpoint overflow signal handler",
93 .func = test__bp_signal,
96 .desc = "Test breakpoint overflow sampling",
97 .func = test__bp_signal_overflow,
100 .desc = "Test number of exit event of a simple workload",
101 .func = test__task_exit,
104 .desc = "Test software clock events have valid period values",
105 .func = test__sw_clock_freq,
107 #if defined(__x86_64__) || defined(__i386__)
109 .desc = "Test converting perf time to TSC",
110 .func = test__perf_time_to_tsc,
112 #endif
114 .desc = "Test object code reading",
115 .func = test__code_reading,
118 .desc = "Test sample parsing",
119 .func = test__sample_parsing,
122 .desc = "Test using a dummy software event to keep tracking",
123 .func = test__keep_tracking,
126 .desc = "Test parsing with no sample_id_all bit set",
127 .func = test__parse_no_sample_id_all,
129 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
130 #ifdef HAVE_DWARF_UNWIND_SUPPORT
132 .desc = "Test dwarf unwind",
133 .func = test__dwarf_unwind,
135 #endif
136 #endif
138 .desc = "Test filtering hist entries",
139 .func = test__hists_filter,
142 .desc = "Test mmap thread lookup",
143 .func = test__mmap_thread_lookup,
146 .desc = "Test thread mg sharing",
147 .func = test__thread_mg_share,
150 .desc = "Test output sorting of hist entries",
151 .func = test__hists_output,
154 .desc = "Test cumulation of child hist entries",
155 .func = test__hists_cumulate,
158 .desc = "Test tracking with sched_switch",
159 .func = test__switch_tracking,
162 .desc = "Filter fds with revents mask in a fdarray",
163 .func = test__fdarray__filter,
166 .desc = "Add fd to a fdarray, making it autogrow",
167 .func = test__fdarray__add,
170 .desc = "Test kmod_path__parse function",
171 .func = test__kmod_path__parse,
174 .desc = "Test thread map",
175 .func = test__thread_map,
178 .func = NULL,
182 static bool perf_test__matches(int curr, int argc, const char *argv[])
184 int i;
186 if (argc == 0)
187 return true;
189 for (i = 0; i < argc; ++i) {
190 char *end;
191 long nr = strtoul(argv[i], &end, 10);
193 if (*end == '\0') {
194 if (nr == curr + 1)
195 return true;
196 continue;
199 if (strstr(tests[curr].desc, argv[i]))
200 return true;
203 return false;
206 static int run_test(struct test *test)
208 int status, err = -1, child = fork();
209 char sbuf[STRERR_BUFSIZE];
211 if (child < 0) {
212 pr_err("failed to fork test: %s\n",
213 strerror_r(errno, sbuf, sizeof(sbuf)));
214 return -1;
217 if (!child) {
218 pr_debug("test child forked, pid %d\n", getpid());
219 err = test->func();
220 exit(err);
223 wait(&status);
225 if (WIFEXITED(status)) {
226 err = (signed char)WEXITSTATUS(status);
227 pr_debug("test child finished with %d\n", err);
228 } else if (WIFSIGNALED(status)) {
229 err = -1;
230 pr_debug("test child interrupted\n");
233 return err;
236 static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
238 int i = 0;
239 int width = 0;
241 while (tests[i].func) {
242 int len = strlen(tests[i].desc);
244 if (width < len)
245 width = len;
246 ++i;
249 i = 0;
250 while (tests[i].func) {
251 int curr = i++, err;
253 if (!perf_test__matches(curr, argc, argv))
254 continue;
256 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
258 if (intlist__find(skiplist, i)) {
259 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
260 continue;
263 pr_debug("\n--- start ---\n");
264 err = run_test(&tests[curr]);
265 pr_debug("---- end ----\n%s:", tests[curr].desc);
267 switch (err) {
268 case TEST_OK:
269 pr_info(" Ok\n");
270 break;
271 case TEST_SKIP:
272 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
273 break;
274 case TEST_FAIL:
275 default:
276 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
277 break;
281 return 0;
284 static int perf_test__list(int argc, const char **argv)
286 int i = 0;
288 while (tests[i].func) {
289 int curr = i++;
291 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
292 continue;
294 pr_info("%2d: %s\n", i, tests[curr].desc);
297 return 0;
300 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
302 const char *test_usage[] = {
303 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
304 NULL,
306 const char *skip = NULL;
307 const struct option test_options[] = {
308 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
309 OPT_INCR('v', "verbose", &verbose,
310 "be more verbose (show symbol address, etc)"),
311 OPT_END()
313 const char * const test_subcommands[] = { "list", NULL };
314 struct intlist *skiplist = NULL;
315 int ret = hists__init();
317 if (ret < 0)
318 return ret;
320 argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
321 if (argc >= 1 && !strcmp(argv[0], "list"))
322 return perf_test__list(argc, argv);
324 symbol_conf.priv_size = sizeof(int);
325 symbol_conf.sort_by_name = true;
326 symbol_conf.try_vmlinux_path = true;
328 if (symbol__init(NULL) < 0)
329 return -1;
331 if (skip != NULL)
332 skiplist = intlist__new(skip);
334 return __cmd_test(argc, argv, skiplist);