4 * Builtin regression testing command: ever growing number of sanity tests
14 #include "parse-options.h"
17 struct test __weak arch_tests[] = {
23 static struct test generic_tests[] = {
25 .desc = "vmlinux symtab matches kallsyms",
26 .func = test__vmlinux_matches_kallsyms,
29 .desc = "detect openat syscall event",
30 .func = test__openat_syscall_event,
33 .desc = "detect openat syscall event on all cpus",
34 .func = test__openat_syscall_event_on_all_cpus,
37 .desc = "read samples using the mmap interface",
38 .func = test__basic_mmap,
41 .desc = "parse events tests",
42 .func = test__parse_events,
44 #if defined(__x86_64__) || defined(__i386__)
46 .desc = "x86 rdpmc test",
51 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
52 .func = test__PERF_RECORD,
55 .desc = "Test perf pmu format parsing",
59 .desc = "Test dso data read",
60 .func = test__dso_data,
63 .desc = "Test dso data cache",
64 .func = test__dso_data_cache,
67 .desc = "Test dso data reopen",
68 .func = test__dso_data_reopen,
71 .desc = "roundtrip evsel->name check",
72 .func = test__perf_evsel__roundtrip_name_test,
75 .desc = "Check parsing of sched tracepoints fields",
76 .func = test__perf_evsel__tp_sched_test,
79 .desc = "Generate and check syscalls:sys_enter_openat event fields",
80 .func = test__syscall_openat_tp_fields,
83 .desc = "struct perf_event_attr setup",
87 .desc = "Test matching and linking multiple hists",
88 .func = test__hists_link,
91 .desc = "Try 'import perf' in python, checking link problems",
92 .func = test__python_use,
95 .desc = "Test breakpoint overflow signal handler",
96 .func = test__bp_signal,
99 .desc = "Test breakpoint overflow sampling",
100 .func = test__bp_signal_overflow,
103 .desc = "Test number of exit event of a simple workload",
104 .func = test__task_exit,
107 .desc = "Test software clock events have valid period values",
108 .func = test__sw_clock_freq,
110 #if defined(__x86_64__) || defined(__i386__)
112 .desc = "Test converting perf time to TSC",
113 .func = test__perf_time_to_tsc,
117 .desc = "Test object code reading",
118 .func = test__code_reading,
121 .desc = "Test sample parsing",
122 .func = test__sample_parsing,
125 .desc = "Test using a dummy software event to keep tracking",
126 .func = test__keep_tracking,
129 .desc = "Test parsing with no sample_id_all bit set",
130 .func = test__parse_no_sample_id_all,
132 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
133 #ifdef HAVE_DWARF_UNWIND_SUPPORT
135 .desc = "Test dwarf unwind",
136 .func = test__dwarf_unwind,
141 .desc = "Test filtering hist entries",
142 .func = test__hists_filter,
145 .desc = "Test mmap thread lookup",
146 .func = test__mmap_thread_lookup,
149 .desc = "Test thread mg sharing",
150 .func = test__thread_mg_share,
153 .desc = "Test output sorting of hist entries",
154 .func = test__hists_output,
157 .desc = "Test cumulation of child hist entries",
158 .func = test__hists_cumulate,
161 .desc = "Test tracking with sched_switch",
162 .func = test__switch_tracking,
165 .desc = "Filter fds with revents mask in a fdarray",
166 .func = test__fdarray__filter,
169 .desc = "Add fd to a fdarray, making it autogrow",
170 .func = test__fdarray__add,
173 .desc = "Test kmod_path__parse function",
174 .func = test__kmod_path__parse,
177 .desc = "Test thread map",
178 .func = test__thread_map,
181 .desc = "Test LLVM searching and compiling",
184 #ifdef HAVE_AUXTRACE_SUPPORT
185 #if defined(__x86_64__) || defined(__i386__)
187 .desc = "Test x86 instruction decoder - new instructions",
188 .func = test__insn_x86,
193 .desc = "Test topology in session",
194 .func = test_session_topology,
201 static struct test *tests[] = {
206 static bool perf_test__matches(struct test *test, int curr, int argc, const char *argv[])
213 for (i = 0; i < argc; ++i) {
215 long nr = strtoul(argv[i], &end, 10);
223 if (strstr(test->desc, argv[i]))
230 static int run_test(struct test *test)
232 int status, err = -1, child = fork();
233 char sbuf[STRERR_BUFSIZE];
236 pr_err("failed to fork test: %s\n",
237 strerror_r(errno, sbuf, sizeof(sbuf)));
242 pr_debug("test child forked, pid %d\n", getpid());
249 if (WIFEXITED(status)) {
250 err = (signed char)WEXITSTATUS(status);
251 pr_debug("test child finished with %d\n", err);
252 } else if (WIFSIGNALED(status)) {
254 pr_debug("test child interrupted\n");
260 #define for_each_test(j, t) \
261 for (j = 0; j < ARRAY_SIZE(tests); j++) \
262 for (t = &tests[j][0]; t->func; t++)
264 static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
271 for_each_test(j, t) {
272 int len = strlen(t->desc);
278 for_each_test(j, t) {
281 if (!perf_test__matches(t, curr, argc, argv))
284 pr_info("%2d: %-*s:", i, width, t->desc);
286 if (intlist__find(skiplist, i)) {
287 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
291 pr_debug("\n--- start ---\n");
293 pr_debug("---- end ----\n%s:", t->desc);
300 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
304 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
312 static int perf_test__list(int argc, const char **argv)
318 for_each_test(j, t) {
319 if (argc > 1 && !strstr(t->desc, argv[1]))
322 pr_info("%2d: %s\n", ++i, t->desc);
328 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
330 const char *test_usage[] = {
331 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
334 const char *skip = NULL;
335 const struct option test_options[] = {
336 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
337 OPT_INCR('v', "verbose", &verbose,
338 "be more verbose (show symbol address, etc)"),
341 const char * const test_subcommands[] = { "list", NULL };
342 struct intlist *skiplist = NULL;
343 int ret = hists__init();
348 argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
349 if (argc >= 1 && !strcmp(argv[0], "list"))
350 return perf_test__list(argc, argv);
352 symbol_conf.priv_size = sizeof(int);
353 symbol_conf.sort_by_name = true;
354 symbol_conf.try_vmlinux_path = true;
356 if (symbol__init(NULL) < 0)
360 skiplist = intlist__new(skip);
362 return __cmd_test(argc, argv, skiplist);