blob: 3ccfd58a8c3cf3e8b16cc513a67324b8f11eae7b [file] [log] [blame]
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -03001/*
2 * builtin-test.c
3 *
4 * Builtin regression testing command: ever growing number of sanity tests
5 */
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -03006#include <errno.h>
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +02007#include <unistd.h>
8#include <string.h>
Arnaldo Carvalho de Melo42087352017-04-19 19:06:30 -03009#include <sys/wait.h>
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030010#include "builtin.h"
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -030011#include "hist.h"
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -030012#include "intlist.h"
Jiri Olsa0a4e1ae2012-11-10 01:46:41 +010013#include "tests.h"
Jiri Olsac81251e2012-11-10 01:46:51 +010014#include "debug.h"
15#include "color.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060016#include <subcmd/parse-options.h>
Jiri Olsac81251e2012-11-10 01:46:51 +010017#include "symbol.h"
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -030018#include <linux/kernel.h>
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020019
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +020020static bool dont_fork;
21
Matt Fleming31b67532015-10-05 15:40:19 +010022struct test __weak arch_tests[] = {
23 {
24 .func = NULL,
25 },
26};
27
28static struct test generic_tests[] = {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030029 {
30 .desc = "vmlinux symtab matches kallsyms",
31 .func = test__vmlinux_matches_kallsyms,
32 },
33 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030034 .desc = "Detect openat syscall event",
Riku Voipio43f322b2015-04-16 16:52:53 +030035 .func = test__openat_syscall_event,
Arnaldo Carvalho de Melod8548612011-01-04 00:16:20 -020036 },
37 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030038 .desc = "Detect openat syscall event on all cpus",
Riku Voipio43f322b2015-04-16 16:52:53 +030039 .func = test__openat_syscall_event_on_all_cpus,
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020040 },
41 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030042 .desc = "Read samples using the mmap interface",
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020043 .func = test__basic_mmap,
44 },
45 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030046 .desc = "Parse event definition strings",
Jiri Olsac81251e2012-11-10 01:46:51 +010047 .func = test__parse_events,
Jiri Olsa13b62562011-07-14 11:25:33 +020048 },
49 {
Andi Kleen07516732017-03-20 13:17:05 -070050 .desc = "Simple expression parser",
51 .func = test__expr,
52 },
53 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030054 .desc = "PERF_RECORD_* events & perf_sample fields",
Arnaldo Carvalho de Melo3e7c4392011-12-02 11:13:50 -020055 .func = test__PERF_RECORD,
56 },
57 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030058 .desc = "Parse perf pmu format",
Jiri Olsacff7f952012-11-10 01:46:50 +010059 .func = test__pmu,
Jiri Olsacd82a322012-03-15 20:09:17 +010060 },
61 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030062 .desc = "DSO data read",
Jiri Olsac81251e2012-11-10 01:46:51 +010063 .func = test__dso_data,
Jiri Olsaf7add552012-07-22 14:14:40 +020064 },
65 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030066 .desc = "DSO data cache",
Jiri Olsa4ebbcb82014-05-12 14:43:53 +020067 .func = test__dso_data_cache,
68 },
69 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030070 .desc = "DSO data reopen",
Jiri Olsa45dc1bb52014-05-12 14:50:03 +020071 .func = test__dso_data_reopen,
72 },
73 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030074 .desc = "Roundtrip evsel->name",
Jiri Olsacfffae22012-11-10 01:46:47 +010075 .func = test__perf_evsel__roundtrip_name_test,
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030076 },
77 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030078 .desc = "Parse sched tracepoints fields",
Jiri Olsa5e24a092012-11-10 01:46:48 +010079 .func = test__perf_evsel__tp_sched_test,
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030080 },
81 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030082 .desc = "syscalls:sys_enter_openat event fields",
Riku Voipio43f322b2015-04-16 16:52:53 +030083 .func = test__syscall_openat_tp_fields,
Arnaldo Carvalho de Meloeb2f2702012-09-26 13:23:10 -030084 },
85 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030086 .desc = "Setup struct perf_event_attr",
Jiri Olsac81251e2012-11-10 01:46:51 +010087 .func = test__attr,
Jiri Olsad898b242012-10-30 23:02:05 +010088 },
89 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030090 .desc = "Match and link multiple hists",
Namhyung Kimf8ebb0c2012-12-10 17:29:57 +090091 .func = test__hists_link,
92 },
93 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030094 .desc = "'import perf' in python",
Arnaldo Carvalho de Melo54359d32012-12-14 13:06:13 -030095 .func = test__python_use,
96 },
97 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030098 .desc = "Breakpoint overflow signal handler",
Jiri Olsa5a6bef42013-03-10 19:41:10 +010099 .func = test__bp_signal,
Jiri Olsa598762c2017-06-01 22:54:50 +0200100 .is_supported = test__bp_signal_is_supported,
Jiri Olsa5a6bef42013-03-10 19:41:10 +0100101 },
102 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300103 .desc = "Breakpoint overflow sampling",
Jiri Olsa06933e32013-03-10 19:41:11 +0100104 .func = test__bp_signal_overflow,
Jiri Olsa598762c2017-06-01 22:54:50 +0200105 .is_supported = test__bp_signal_is_supported,
Jiri Olsa06933e32013-03-10 19:41:11 +0100106 },
107 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300108 .desc = "Number of exit events of a simple workload",
Namhyung Kimd723a552013-03-15 14:58:11 +0900109 .func = test__task_exit,
110 },
111 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300112 .desc = "Software clock events period values",
Namhyung Kimbc96b362013-03-18 11:41:47 +0900113 .func = test__sw_clock_freq,
114 },
115 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300116 .desc = "Object code reading",
Adrian Hunterb55ae0a2013-08-07 14:38:45 +0300117 .func = test__code_reading,
118 },
119 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300120 .desc = "Sample parsing",
Adrian Hunter045f8cd82013-08-27 11:23:13 +0300121 .func = test__sample_parsing,
122 },
123 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300124 .desc = "Use a dummy software event to keep tracking",
Adrian Hunter395c3072013-08-31 21:50:53 +0300125 .func = test__keep_tracking,
126 },
127 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300128 .desc = "Parse with no sample_id_all bit set",
Adrian Hunter53a277e2013-09-04 23:18:16 +0300129 .func = test__parse_no_sample_id_all,
130 },
131 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300132 .desc = "Filter hist entries",
Namhyung Kim3c3cfd92014-04-25 12:28:14 +0900133 .func = test__hists_filter,
134 },
135 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300136 .desc = "Lookup mmap thread",
Jiri Olsa4e85edf2014-03-05 17:20:31 +0100137 .func = test__mmap_thread_lookup,
138 },
139 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300140 .desc = "Share thread mg",
Jiri Olsafabf012382014-03-17 14:39:00 +0100141 .func = test__thread_mg_share,
142 },
143 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300144 .desc = "Sort output of hist entries",
Namhyung Kimf21d1812014-05-12 14:43:18 +0900145 .func = test__hists_output,
146 },
147 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300148 .desc = "Cumulate child hist entries",
Namhyung Kim0506aec2014-05-23 18:04:42 +0900149 .func = test__hists_cumulate,
150 },
151 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300152 .desc = "Track with sched_switch",
Adrian Hunterd44bc552014-08-15 22:08:36 +0300153 .func = test__switch_tracking,
154 },
155 {
Arnaldo Carvalho de Melo1b853372014-09-03 18:02:59 -0300156 .desc = "Filter fds with revents mask in a fdarray",
157 .func = test__fdarray__filter,
Arnaldo Carvalho de Melo54dbfae2014-08-12 23:34:06 -0300158 },
159 {
Arnaldo Carvalho de Melo1b853372014-09-03 18:02:59 -0300160 .desc = "Add fd to a fdarray, making it autogrow",
161 .func = test__fdarray__add,
Arnaldo Carvalho de Melo9ae28032014-08-18 16:49:00 -0300162 },
163 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300164 .desc = "kmod_path__parse",
Jiri Olsa3c8a67f2015-02-05 15:40:25 +0100165 .func = test__kmod_path__parse,
166 },
167 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300168 .desc = "Thread map",
Jiri Olsa134aa442015-06-26 11:29:08 +0200169 .func = test__thread_map,
170 },
171 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300172 .desc = "LLVM search and compile",
Wang Nan9bc898c2015-07-08 10:04:02 +0000173 .func = test__llvm,
Wang Nane8c6d502015-11-17 08:32:48 +0000174 .subtest = {
175 .skip_if_fail = true,
176 .get_nr = test__llvm_subtest_get_nr,
177 .get_desc = test__llvm_subtest_get_desc,
178 },
Wang Nan9bc898c2015-07-08 10:04:02 +0000179 },
180 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300181 .desc = "Session topology",
Kan Liangc84974e2015-09-04 04:58:31 -0400182 .func = test_session_topology,
183 },
184 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300185 .desc = "BPF filter",
Wang Nanba1fae42015-11-06 13:49:43 +0000186 .func = test__bpf,
Wang Nan77a0cf62015-11-17 08:32:49 +0000187 .subtest = {
188 .skip_if_fail = true,
189 .get_nr = test__bpf_subtest_get_nr,
190 .get_desc = test__bpf_subtest_get_desc,
191 },
Wang Nanba1fae42015-11-06 13:49:43 +0000192 },
193 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300194 .desc = "Synthesize thread map",
Jiri Olsa99471c92015-10-25 15:51:20 +0100195 .func = test__thread_map_synthesize,
196 },
197 {
Jiri Olsa38af91f2016-12-12 11:35:41 +0100198 .desc = "Remove thread map",
199 .func = test__thread_map_remove,
200 },
201 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300202 .desc = "Synthesize cpu map",
Jiri Olsa6c872902015-10-25 15:51:24 +0100203 .func = test__cpu_map_synthesize,
204 },
205 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300206 .desc = "Synthesize stat config",
Jiri Olsa67424342015-10-25 15:51:28 +0100207 .func = test__synthesize_stat_config,
208 },
209 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300210 .desc = "Synthesize stat",
Jiri Olsa5796f8f2015-10-25 15:51:31 +0100211 .func = test__synthesize_stat,
212 },
213 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300214 .desc = "Synthesize stat round",
Jiri Olsad4c22592015-10-25 15:51:34 +0100215 .func = test__synthesize_stat_round,
216 },
217 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300218 .desc = "Synthesize attr update",
Jiri Olsaa6e52812015-10-25 15:51:37 +0100219 .func = test__event_update,
220 },
221 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300222 .desc = "Event times",
Jiri Olsab31d6602016-03-24 13:52:20 +0100223 .func = test__event_times,
224 },
225 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300226 .desc = "Read backward ring buffer",
Wang Nanee747012016-05-09 01:47:51 +0000227 .func = test__backward_ring_buffer,
228 },
229 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300230 .desc = "Print cpu map",
Jiri Olsaa24020e2016-06-28 13:29:04 +0200231 .func = test__cpu_map_print,
232 },
233 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300234 .desc = "Probe SDT events",
Masami Hiramatsu8e5dc842016-07-12 19:06:05 +0900235 .func = test__sdt_event,
236 },
237 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300238 .desc = "is_printable_array",
Jiri Olsa988dd772016-07-16 18:11:20 +0200239 .func = test__is_printable_array,
240 },
241 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300242 .desc = "Print bitmap",
Jiri Olsaff3e33b2016-08-01 20:02:32 +0200243 .func = test__bitmap_print,
244 },
245 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300246 .desc = "perf hooks",
Wang Nana0748652016-11-26 07:03:28 +0000247 .func = test__perf_hooks,
248 },
249 {
Wang Nan00b86692016-11-26 07:03:34 +0000250 .desc = "builtin clang support",
251 .func = test__clang,
252 .subtest = {
253 .skip_if_fail = true,
254 .get_nr = test__clang_subtest_get_nr,
255 .get_desc = test__clang_subtest_get_desc,
256 }
257 },
258 {
Jiri Olsa98081432017-01-09 10:51:55 +0100259 .desc = "unit_number__scnprintf",
260 .func = test__unit_number__scnprint,
261 },
262 {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300263 .func = NULL,
264 },
265};
266
Matt Fleming31b67532015-10-05 15:40:19 +0100267static struct test *tests[] = {
268 generic_tests,
269 arch_tests,
270};
271
Matt Fleminge8210ce2015-09-05 20:02:20 +0100272static bool perf_test__matches(struct test *test, int curr, int argc, const char *argv[])
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200273{
274 int i;
275
276 if (argc == 0)
277 return true;
278
279 for (i = 0; i < argc; ++i) {
280 char *end;
281 long nr = strtoul(argv[i], &end, 10);
282
283 if (*end == '\0') {
284 if (nr == curr + 1)
285 return true;
286 continue;
287 }
288
Arnaldo Carvalho de Melo345c99a2015-11-06 17:03:38 -0300289 if (strcasestr(test->desc, argv[i]))
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200290 return true;
291 }
292
293 return false;
294}
295
Arnaldo Carvalho de Melo721a1f52015-11-19 12:01:48 -0300296static int run_test(struct test *test, int subtest)
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200297{
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200298 int status, err = -1, child = dont_fork ? 0 : fork();
Masami Hiramatsuba3dfff2014-08-14 02:22:45 +0000299 char sbuf[STRERR_BUFSIZE];
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200300
301 if (child < 0) {
Masami Hiramatsuba3dfff2014-08-14 02:22:45 +0000302 pr_err("failed to fork test: %s\n",
Arnaldo Carvalho de Meloc8b5f2c2016-07-06 11:56:20 -0300303 str_error_r(errno, sbuf, sizeof(sbuf)));
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200304 return -1;
305 }
306
307 if (!child) {
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200308 if (!dont_fork) {
309 pr_debug("test child forked, pid %d\n", getpid());
Wang Nan5bcf2fe2015-11-17 08:32:50 +0000310
Namhyung Kimbb963e12017-02-17 17:17:38 +0900311 if (verbose <= 0) {
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200312 int nullfd = open("/dev/null", O_WRONLY);
313
314 if (nullfd >= 0) {
315 close(STDERR_FILENO);
316 close(STDOUT_FILENO);
317
318 dup2(nullfd, STDOUT_FILENO);
319 dup2(STDOUT_FILENO, STDERR_FILENO);
320 close(nullfd);
321 }
322 } else {
323 signal(SIGSEGV, sighandler_dump_stack);
324 signal(SIGFPE, sighandler_dump_stack);
Wang Nan5bcf2fe2015-11-17 08:32:50 +0000325 }
326 }
327
Arnaldo Carvalho de Melo721a1f52015-11-19 12:01:48 -0300328 err = test->func(subtest);
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200329 if (!dont_fork)
330 exit(err);
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200331 }
332
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200333 if (!dont_fork) {
334 wait(&status);
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200335
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200336 if (WIFEXITED(status)) {
337 err = (signed char)WEXITSTATUS(status);
338 pr_debug("test child finished with %d\n", err);
339 } else if (WIFSIGNALED(status)) {
340 err = -1;
341 pr_debug("test child interrupted\n");
342 }
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200343 }
344
345 return err;
346}
347
Matt Fleming31b67532015-10-05 15:40:19 +0100348#define for_each_test(j, t) \
349 for (j = 0; j < ARRAY_SIZE(tests); j++) \
350 for (t = &tests[j][0]; t->func; t++)
Matt Fleminge8210ce2015-09-05 20:02:20 +0100351
Wang Nane8c6d502015-11-17 08:32:48 +0000352static int test_and_print(struct test *t, bool force_skip, int subtest)
353{
354 int err;
355
356 if (!force_skip) {
357 pr_debug("\n--- start ---\n");
358 err = run_test(t, subtest);
359 pr_debug("---- end ----\n");
360 } else {
361 pr_debug("\n--- force skipped ---\n");
362 err = TEST_SKIP;
363 }
364
365 if (!t->subtest.get_nr)
366 pr_debug("%s:", t->desc);
367 else
368 pr_debug("%s subtest %d:", t->desc, subtest);
369
370 switch (err) {
371 case TEST_OK:
372 pr_info(" Ok\n");
373 break;
374 case TEST_SKIP:
375 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
376 break;
377 case TEST_FAIL:
378 default:
379 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
380 break;
381 }
382
383 return err;
384}
385
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300386static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300387{
Matt Fleminge8210ce2015-09-05 20:02:20 +0100388 struct test *t;
Matt Fleming31b67532015-10-05 15:40:19 +0100389 unsigned int j;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300390 int i = 0;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200391 int width = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300392
Matt Fleming31b67532015-10-05 15:40:19 +0100393 for_each_test(j, t) {
Matt Fleminge8210ce2015-09-05 20:02:20 +0100394 int len = strlen(t->desc);
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200395
396 if (width < len)
397 width = len;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200398 }
Jiri Olsa945aea22012-10-30 23:01:43 +0100399
Matt Fleming31b67532015-10-05 15:40:19 +0100400 for_each_test(j, t) {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200401 int curr = i++, err;
402
Matt Fleminge8210ce2015-09-05 20:02:20 +0100403 if (!perf_test__matches(t, curr, argc, argv))
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200404 continue;
405
Jiri Olsa598762c2017-06-01 22:54:50 +0200406 if (t->is_supported && !t->is_supported()) {
407 pr_debug("%2d: %-*s: Disabled\n", i, width, t->desc);
408 continue;
409 }
410
Matt Fleminge8210ce2015-09-05 20:02:20 +0100411 pr_info("%2d: %-*s:", i, width, t->desc);
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300412
413 if (intlist__find(skiplist, i)) {
414 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
415 continue;
416 }
417
Wang Nane8c6d502015-11-17 08:32:48 +0000418 if (!t->subtest.get_nr) {
419 test_and_print(t, false, -1);
420 } else {
421 int subn = t->subtest.get_nr();
422 /*
423 * minus 2 to align with normal testcases.
424 * For subtest we print additional '.x' in number.
425 * for example:
426 *
427 * 35: Test LLVM searching and compiling :
428 * 35.1: Basic BPF llvm compiling test : Ok
429 */
430 int subw = width > 2 ? width - 2 : width;
431 bool skip = false;
432 int subi;
Jiri Olsaf4c1ea52012-12-19 11:33:39 -0300433
Wang Nane8c6d502015-11-17 08:32:48 +0000434 if (subn <= 0) {
435 color_fprintf(stderr, PERF_COLOR_YELLOW,
436 " Skip (not compiled in)\n");
437 continue;
438 }
439 pr_info("\n");
440
441 for (subi = 0; subi < subn; subi++) {
442 int len = strlen(t->subtest.get_desc(subi));
443
444 if (subw < len)
445 subw = len;
446 }
447
448 for (subi = 0; subi < subn; subi++) {
449 pr_info("%2d.%1d: %-*s:", i, subi + 1, subw,
450 t->subtest.get_desc(subi));
451 err = test_and_print(t, skip, subi);
452 if (err != TEST_OK && t->subtest.skip_if_fail)
453 skip = true;
454 }
Jiri Olsaf4c1ea52012-12-19 11:33:39 -0300455 }
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300456 }
457
458 return 0;
459}
460
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200461static int perf_test__list(int argc, const char **argv)
462{
Matt Fleming31b67532015-10-05 15:40:19 +0100463 unsigned int j;
Matt Fleminge8210ce2015-09-05 20:02:20 +0100464 struct test *t;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200465 int i = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300466
Matt Fleming31b67532015-10-05 15:40:19 +0100467 for_each_test(j, t) {
Matt Fleminge8210ce2015-09-05 20:02:20 +0100468 if (argc > 1 && !strstr(t->desc, argv[1]))
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200469 continue;
470
Matt Fleminge8210ce2015-09-05 20:02:20 +0100471 pr_info("%2d: %s\n", ++i, t->desc);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200472 }
473
474 return 0;
475}
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300476
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -0300477int cmd_test(int argc, const char **argv)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300478{
Yunlong Song1f9975f2015-03-18 21:35:55 +0800479 const char *test_usage[] = {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200480 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
481 NULL,
482 };
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300483 const char *skip = NULL;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200484 const struct option test_options[] = {
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300485 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
Namhyung Kimc30ab8a2012-01-08 02:25:26 +0900486 OPT_INCR('v', "verbose", &verbose,
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200487 "be more verbose (show symbol address, etc)"),
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200488 OPT_BOOLEAN('F', "dont-fork", &dont_fork,
489 "Do not fork for testcase"),
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200490 OPT_END()
491 };
Yunlong Song1f9975f2015-03-18 21:35:55 +0800492 const char * const test_subcommands[] = { "list", NULL };
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300493 struct intlist *skiplist = NULL;
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -0300494 int ret = hists__init();
495
496 if (ret < 0)
497 return ret;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200498
Yunlong Song1f9975f2015-03-18 21:35:55 +0800499 argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200500 if (argc >= 1 && !strcmp(argv[0], "list"))
501 return perf_test__list(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300502
503 symbol_conf.priv_size = sizeof(int);
504 symbol_conf.sort_by_name = true;
505 symbol_conf.try_vmlinux_path = true;
506
Namhyung Kim0a7e6d12014-08-12 15:40:45 +0900507 if (symbol__init(NULL) < 0)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300508 return -1;
509
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300510 if (skip != NULL)
511 skiplist = intlist__new(skip);
512
513 return __cmd_test(argc, argv, skiplist);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300514}