4 * Builtin regression testing command: ever growing number of sanity tests
13 #include "parse-options.h"
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",
47 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
48 .func = test__PERF_RECORD,
51 .desc = "Test perf pmu format parsing",
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 = "roundtrip evsel->name check",
64 .func = test__perf_evsel__roundtrip_name_test,
67 .desc = "Check parsing of sched tracepoints fields",
68 .func = test__perf_evsel__tp_sched_test,
71 .desc = "Generate and check syscalls:sys_enter_open event fields",
72 .func = test__syscall_open_tp_fields,
75 .desc = "struct perf_event_attr setup",
79 .desc = "Test matching and linking multiple hists",
80 .func = test__hists_link,
83 .desc = "Try 'use perf' in python, checking link problems",
84 .func = test__python_use,
87 .desc = "Test breakpoint overflow signal handler",
88 .func = test__bp_signal,
91 .desc = "Test breakpoint overflow sampling",
92 .func = test__bp_signal_overflow,
95 .desc = "Test number of exit event of a simple workload",
96 .func = test__task_exit,
99 .desc = "Test software clock events have valid period values",
100 .func = test__sw_clock_freq,
102 #if defined(__x86_64__) || defined(__i386__)
104 .desc = "Test converting perf time to TSC",
105 .func = test__perf_time_to_tsc,
109 .desc = "Test object code reading",
110 .func = test__code_reading,
113 .desc = "Test sample parsing",
114 .func = test__sample_parsing,
117 .desc = "Test using a dummy software event to keep tracking",
118 .func = test__keep_tracking,
121 .desc = "Test parsing with no sample_id_all bit set",
122 .func = test__parse_no_sample_id_all,
124 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
125 #ifdef HAVE_DWARF_UNWIND_SUPPORT
127 .desc = "Test dwarf unwind",
128 .func = test__dwarf_unwind,
133 .desc = "Test filtering hist entries",
134 .func = test__hists_filter,
137 .desc = "Test mmap thread lookup",
138 .func = test__mmap_thread_lookup,
141 .desc = "Test thread mg sharing",
142 .func = test__thread_mg_share,
145 .desc = "Test output sorting of hist entries",
146 .func = test__hists_output,
149 .desc = "Test cumulation of child hist entries",
150 .func = test__hists_cumulate,
157 static bool perf_test__matches(int curr, int argc, const char *argv[])
164 for (i = 0; i < argc; ++i) {
166 long nr = strtoul(argv[i], &end, 10);
174 if (strstr(tests[curr].desc, argv[i]))
181 static int run_test(struct test *test)
183 int status, err = -1, child = fork();
186 pr_err("failed to fork test: %s\n", strerror(errno));
191 pr_debug("test child forked, pid %d\n", getpid());
198 if (WIFEXITED(status)) {
199 err = WEXITSTATUS(status);
200 pr_debug("test child finished with %d\n", err);
201 } else if (WIFSIGNALED(status)) {
203 pr_debug("test child interrupted\n");
209 static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
214 while (tests[i].func) {
215 int len = strlen(tests[i].desc);
223 while (tests[i].func) {
226 if (!perf_test__matches(curr, argc, argv))
229 pr_info("%2d: %-*s:", i, width, tests[curr].desc);
231 if (intlist__find(skiplist, i)) {
232 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
236 pr_debug("\n--- start ---\n");
237 err = run_test(&tests[curr]);
238 pr_debug("---- end ----\n%s:", tests[curr].desc);
245 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
249 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
257 static int perf_test__list(int argc, const char **argv)
261 while (tests[i].func) {
264 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
267 pr_info("%2d: %s\n", i, tests[curr].desc);
273 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
275 const char * const test_usage[] = {
276 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
279 const char *skip = NULL;
280 const struct option test_options[] = {
281 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
282 OPT_INCR('v', "verbose", &verbose,
283 "be more verbose (show symbol address, etc)"),
286 struct intlist *skiplist = NULL;
288 argc = parse_options(argc, argv, test_options, test_usage, 0);
289 if (argc >= 1 && !strcmp(argv[0], "list"))
290 return perf_test__list(argc, argv);
292 symbol_conf.priv_size = sizeof(int);
293 symbol_conf.sort_by_name = true;
294 symbol_conf.try_vmlinux_path = true;
296 if (symbol__init() < 0)
300 skiplist = intlist__new(skip);
302 return __cmd_test(argc, argv, skiplist);