4 * Builtin regression testing command: ever growing number of sanity tests
16 #include <subcmd/parse-options.h>
18 #include <linux/kernel.h>
20 static bool dont_fork
;
22 struct test __weak arch_tests
[] = {
28 static struct test generic_tests
[] = {
30 .desc
= "vmlinux symtab matches kallsyms",
31 .func
= test__vmlinux_matches_kallsyms
,
34 .desc
= "Detect openat syscall event",
35 .func
= test__openat_syscall_event
,
38 .desc
= "Detect openat syscall event on all cpus",
39 .func
= test__openat_syscall_event_on_all_cpus
,
42 .desc
= "Read samples using the mmap interface",
43 .func
= test__basic_mmap
,
46 .desc
= "Parse event definition strings",
47 .func
= test__parse_events
,
50 .desc
= "Simple expression parser",
54 .desc
= "PERF_RECORD_* events & perf_sample fields",
55 .func
= test__PERF_RECORD
,
58 .desc
= "Parse perf pmu format",
62 .desc
= "DSO data read",
63 .func
= test__dso_data
,
66 .desc
= "DSO data cache",
67 .func
= test__dso_data_cache
,
70 .desc
= "DSO data reopen",
71 .func
= test__dso_data_reopen
,
74 .desc
= "Roundtrip evsel->name",
75 .func
= test__perf_evsel__roundtrip_name_test
,
78 .desc
= "Parse sched tracepoints fields",
79 .func
= test__perf_evsel__tp_sched_test
,
82 .desc
= "syscalls:sys_enter_openat event fields",
83 .func
= test__syscall_openat_tp_fields
,
86 .desc
= "Setup struct perf_event_attr",
90 .desc
= "Match and link multiple hists",
91 .func
= test__hists_link
,
94 .desc
= "'import perf' in python",
95 .func
= test__python_use
,
98 .desc
= "Breakpoint overflow signal handler",
99 .func
= test__bp_signal
,
102 .desc
= "Breakpoint overflow sampling",
103 .func
= test__bp_signal_overflow
,
106 .desc
= "Number of exit events of a simple workload",
107 .func
= test__task_exit
,
110 .desc
= "Software clock events period values",
111 .func
= test__sw_clock_freq
,
114 .desc
= "Object code reading",
115 .func
= test__code_reading
,
118 .desc
= "Sample parsing",
119 .func
= test__sample_parsing
,
122 .desc
= "Use a dummy software event to keep tracking",
123 .func
= test__keep_tracking
,
126 .desc
= "Parse with no sample_id_all bit set",
127 .func
= test__parse_no_sample_id_all
,
130 .desc
= "Filter hist entries",
131 .func
= test__hists_filter
,
134 .desc
= "Lookup mmap thread",
135 .func
= test__mmap_thread_lookup
,
138 .desc
= "Share thread mg",
139 .func
= test__thread_mg_share
,
142 .desc
= "Sort output of hist entries",
143 .func
= test__hists_output
,
146 .desc
= "Cumulate child hist entries",
147 .func
= test__hists_cumulate
,
150 .desc
= "Track with sched_switch",
151 .func
= test__switch_tracking
,
154 .desc
= "Filter fds with revents mask in a fdarray",
155 .func
= test__fdarray__filter
,
158 .desc
= "Add fd to a fdarray, making it autogrow",
159 .func
= test__fdarray__add
,
162 .desc
= "kmod_path__parse",
163 .func
= test__kmod_path__parse
,
166 .desc
= "Thread map",
167 .func
= test__thread_map
,
170 .desc
= "LLVM search and compile",
173 .skip_if_fail
= true,
174 .get_nr
= test__llvm_subtest_get_nr
,
175 .get_desc
= test__llvm_subtest_get_desc
,
179 .desc
= "Session topology",
180 .func
= test_session_topology
,
183 .desc
= "BPF filter",
186 .skip_if_fail
= true,
187 .get_nr
= test__bpf_subtest_get_nr
,
188 .get_desc
= test__bpf_subtest_get_desc
,
192 .desc
= "Synthesize thread map",
193 .func
= test__thread_map_synthesize
,
196 .desc
= "Remove thread map",
197 .func
= test__thread_map_remove
,
200 .desc
= "Synthesize cpu map",
201 .func
= test__cpu_map_synthesize
,
204 .desc
= "Synthesize stat config",
205 .func
= test__synthesize_stat_config
,
208 .desc
= "Synthesize stat",
209 .func
= test__synthesize_stat
,
212 .desc
= "Synthesize stat round",
213 .func
= test__synthesize_stat_round
,
216 .desc
= "Synthesize attr update",
217 .func
= test__event_update
,
220 .desc
= "Event times",
221 .func
= test__event_times
,
224 .desc
= "Read backward ring buffer",
225 .func
= test__backward_ring_buffer
,
228 .desc
= "Print cpu map",
229 .func
= test__cpu_map_print
,
232 .desc
= "Probe SDT events",
233 .func
= test__sdt_event
,
236 .desc
= "is_printable_array",
237 .func
= test__is_printable_array
,
240 .desc
= "Print bitmap",
241 .func
= test__bitmap_print
,
244 .desc
= "perf hooks",
245 .func
= test__perf_hooks
,
248 .desc
= "builtin clang support",
251 .skip_if_fail
= true,
252 .get_nr
= test__clang_subtest_get_nr
,
253 .get_desc
= test__clang_subtest_get_desc
,
257 .desc
= "unit_number__scnprintf",
258 .func
= test__unit_number__scnprint
,
265 static struct test
*tests
[] = {
270 static bool perf_test__matches(struct test
*test
, int curr
, int argc
, const char *argv
[])
277 for (i
= 0; i
< argc
; ++i
) {
279 long nr
= strtoul(argv
[i
], &end
, 10);
287 if (strcasestr(test
->desc
, argv
[i
]))
294 static int run_test(struct test
*test
, int subtest
)
296 int status
, err
= -1, child
= dont_fork
? 0 : fork();
297 char sbuf
[STRERR_BUFSIZE
];
300 pr_err("failed to fork test: %s\n",
301 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
307 pr_debug("test child forked, pid %d\n", getpid());
310 int nullfd
= open("/dev/null", O_WRONLY
);
313 close(STDERR_FILENO
);
314 close(STDOUT_FILENO
);
316 dup2(nullfd
, STDOUT_FILENO
);
317 dup2(STDOUT_FILENO
, STDERR_FILENO
);
321 signal(SIGSEGV
, sighandler_dump_stack
);
322 signal(SIGFPE
, sighandler_dump_stack
);
326 err
= test
->func(subtest
);
334 if (WIFEXITED(status
)) {
335 err
= (signed char)WEXITSTATUS(status
);
336 pr_debug("test child finished with %d\n", err
);
337 } else if (WIFSIGNALED(status
)) {
339 pr_debug("test child interrupted\n");
346 #define for_each_test(j, t) \
347 for (j = 0; j < ARRAY_SIZE(tests); j++) \
348 for (t = &tests[j][0]; t->func; t++)
350 static int test_and_print(struct test
*t
, bool force_skip
, int subtest
)
355 pr_debug("\n--- start ---\n");
356 err
= run_test(t
, subtest
);
357 pr_debug("---- end ----\n");
359 pr_debug("\n--- force skipped ---\n");
363 if (!t
->subtest
.get_nr
)
364 pr_debug("%s:", t
->desc
);
366 pr_debug("%s subtest %d:", t
->desc
, subtest
);
373 color_fprintf(stderr
, PERF_COLOR_YELLOW
, " Skip\n");
377 color_fprintf(stderr
, PERF_COLOR_RED
, " FAILED!\n");
384 static int __cmd_test(int argc
, const char *argv
[], struct intlist
*skiplist
)
391 for_each_test(j
, t
) {
392 int len
= strlen(t
->desc
);
398 for_each_test(j
, t
) {
401 if (!perf_test__matches(t
, curr
, argc
, argv
))
404 pr_info("%2d: %-*s:", i
, width
, t
->desc
);
406 if (intlist__find(skiplist
, i
)) {
407 color_fprintf(stderr
, PERF_COLOR_YELLOW
, " Skip (user override)\n");
411 if (!t
->subtest
.get_nr
) {
412 test_and_print(t
, false, -1);
414 int subn
= t
->subtest
.get_nr();
416 * minus 2 to align with normal testcases.
417 * For subtest we print additional '.x' in number.
420 * 35: Test LLVM searching and compiling :
421 * 35.1: Basic BPF llvm compiling test : Ok
423 int subw
= width
> 2 ? width
- 2 : width
;
428 color_fprintf(stderr
, PERF_COLOR_YELLOW
,
429 " Skip (not compiled in)\n");
434 for (subi
= 0; subi
< subn
; subi
++) {
435 int len
= strlen(t
->subtest
.get_desc(subi
));
441 for (subi
= 0; subi
< subn
; subi
++) {
442 pr_info("%2d.%1d: %-*s:", i
, subi
+ 1, subw
,
443 t
->subtest
.get_desc(subi
));
444 err
= test_and_print(t
, skip
, subi
);
445 if (err
!= TEST_OK
&& t
->subtest
.skip_if_fail
)
454 static int perf_test__list(int argc
, const char **argv
)
460 for_each_test(j
, t
) {
461 if (argc
> 1 && !strstr(t
->desc
, argv
[1]))
464 pr_info("%2d: %s\n", ++i
, t
->desc
);
470 int cmd_test(int argc
, const char **argv
)
472 const char *test_usage
[] = {
473 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
476 const char *skip
= NULL
;
477 const struct option test_options
[] = {
478 OPT_STRING('s', "skip", &skip
, "tests", "tests to skip"),
479 OPT_INCR('v', "verbose", &verbose
,
480 "be more verbose (show symbol address, etc)"),
481 OPT_BOOLEAN('F', "dont-fork", &dont_fork
,
482 "Do not fork for testcase"),
485 const char * const test_subcommands
[] = { "list", NULL
};
486 struct intlist
*skiplist
= NULL
;
487 int ret
= hists__init();
492 argc
= parse_options_subcommand(argc
, argv
, test_options
, test_subcommands
, test_usage
, 0);
493 if (argc
>= 1 && !strcmp(argv
[0], "list"))
494 return perf_test__list(argc
, argv
);
496 symbol_conf
.priv_size
= sizeof(int);
497 symbol_conf
.sort_by_name
= true;
498 symbol_conf
.try_vmlinux_path
= true;
500 if (symbol__init(NULL
) < 0)
504 skiplist
= intlist__new(skip
);
506 return __cmd_test(argc
, argv
, skiplist
);