blob: a77dcc0d24e3f356c9da230cd84a35eddde99852 [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 */
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +02006#include <unistd.h>
7#include <string.h>
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -03008#include "builtin.h"
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -03009#include "hist.h"
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -030010#include "intlist.h"
Jiri Olsa0a4e1ae2012-11-10 01:46:41 +010011#include "tests.h"
Jiri Olsac81251e2012-11-10 01:46:51 +010012#include "debug.h"
13#include "color.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060014#include <subcmd/parse-options.h>
Jiri Olsac81251e2012-11-10 01:46:51 +010015#include "symbol.h"
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020016
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +020017static bool dont_fork;
18
Matt Fleming31b67532015-10-05 15:40:19 +010019struct test __weak arch_tests[] = {
20 {
21 .func = NULL,
22 },
23};
24
25static struct test generic_tests[] = {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -030026 {
27 .desc = "vmlinux symtab matches kallsyms",
28 .func = test__vmlinux_matches_kallsyms,
29 },
30 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030031 .desc = "Detect openat syscall event",
Riku Voipio43f322b2015-04-16 16:52:53 +030032 .func = test__openat_syscall_event,
Arnaldo Carvalho de Melod8548612011-01-04 00:16:20 -020033 },
34 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030035 .desc = "Detect openat syscall event on all cpus",
Riku Voipio43f322b2015-04-16 16:52:53 +030036 .func = test__openat_syscall_event_on_all_cpus,
Arnaldo Carvalho de Melo02522082011-01-04 11:55:27 -020037 },
38 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030039 .desc = "Read samples using the mmap interface",
Arnaldo Carvalho de Melode5fa3a2011-01-15 10:42:46 -020040 .func = test__basic_mmap,
41 },
42 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030043 .desc = "Parse event definition strings",
Jiri Olsac81251e2012-11-10 01:46:51 +010044 .func = test__parse_events,
Jiri Olsa13b62562011-07-14 11:25:33 +020045 },
46 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030047 .desc = "PERF_RECORD_* events & perf_sample fields",
Arnaldo Carvalho de Melo3e7c4392011-12-02 11:13:50 -020048 .func = test__PERF_RECORD,
49 },
50 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030051 .desc = "Parse perf pmu format",
Jiri Olsacff7f952012-11-10 01:46:50 +010052 .func = test__pmu,
Jiri Olsacd82a322012-03-15 20:09:17 +010053 },
54 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030055 .desc = "DSO data read",
Jiri Olsac81251e2012-11-10 01:46:51 +010056 .func = test__dso_data,
Jiri Olsaf7add552012-07-22 14:14:40 +020057 },
58 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030059 .desc = "DSO data cache",
Jiri Olsa4ebbcb82014-05-12 14:43:53 +020060 .func = test__dso_data_cache,
61 },
62 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030063 .desc = "DSO data reopen",
Jiri Olsa45dc1bb52014-05-12 14:50:03 +020064 .func = test__dso_data_reopen,
65 },
66 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030067 .desc = "Roundtrip evsel->name",
Jiri Olsacfffae22012-11-10 01:46:47 +010068 .func = test__perf_evsel__roundtrip_name_test,
Arnaldo Carvalho de Melo8ad70132012-09-06 13:11:18 -030069 },
70 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030071 .desc = "Parse sched tracepoints fields",
Jiri Olsa5e24a092012-11-10 01:46:48 +010072 .func = test__perf_evsel__tp_sched_test,
Arnaldo Carvalho de Melo6a6cd112012-09-18 11:56:28 -030073 },
74 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030075 .desc = "syscalls:sys_enter_openat event fields",
Riku Voipio43f322b2015-04-16 16:52:53 +030076 .func = test__syscall_openat_tp_fields,
Arnaldo Carvalho de Meloeb2f2702012-09-26 13:23:10 -030077 },
78 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030079 .desc = "Setup struct perf_event_attr",
Jiri Olsac81251e2012-11-10 01:46:51 +010080 .func = test__attr,
Jiri Olsad898b242012-10-30 23:02:05 +010081 },
82 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030083 .desc = "Match and link multiple hists",
Namhyung Kimf8ebb0c2012-12-10 17:29:57 +090084 .func = test__hists_link,
85 },
86 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030087 .desc = "'import perf' in python",
Arnaldo Carvalho de Melo54359d32012-12-14 13:06:13 -030088 .func = test__python_use,
89 },
90 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030091 .desc = "Breakpoint overflow signal handler",
Jiri Olsa5a6bef42013-03-10 19:41:10 +010092 .func = test__bp_signal,
93 },
94 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030095 .desc = "Breakpoint overflow sampling",
Jiri Olsa06933e32013-03-10 19:41:11 +010096 .func = test__bp_signal_overflow,
97 },
98 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -030099 .desc = "Number of exit events of a simple workload",
Namhyung Kimd723a552013-03-15 14:58:11 +0900100 .func = test__task_exit,
101 },
102 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300103 .desc = "Software clock events period values",
Namhyung Kimbc96b362013-03-18 11:41:47 +0900104 .func = test__sw_clock_freq,
105 },
106 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300107 .desc = "Object code reading",
Adrian Hunterb55ae0a2013-08-07 14:38:45 +0300108 .func = test__code_reading,
109 },
110 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300111 .desc = "Sample parsing",
Adrian Hunter045f8cd82013-08-27 11:23:13 +0300112 .func = test__sample_parsing,
113 },
114 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300115 .desc = "Use a dummy software event to keep tracking",
Adrian Hunter395c3072013-08-31 21:50:53 +0300116 .func = test__keep_tracking,
117 },
118 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300119 .desc = "Parse with no sample_id_all bit set",
Adrian Hunter53a277e2013-09-04 23:18:16 +0300120 .func = test__parse_no_sample_id_all,
121 },
122 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300123 .desc = "Filter hist entries",
Namhyung Kim3c3cfd92014-04-25 12:28:14 +0900124 .func = test__hists_filter,
125 },
126 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300127 .desc = "Lookup mmap thread",
Jiri Olsa4e85edf2014-03-05 17:20:31 +0100128 .func = test__mmap_thread_lookup,
129 },
130 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300131 .desc = "Share thread mg",
Jiri Olsafabf012382014-03-17 14:39:00 +0100132 .func = test__thread_mg_share,
133 },
134 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300135 .desc = "Sort output of hist entries",
Namhyung Kimf21d1812014-05-12 14:43:18 +0900136 .func = test__hists_output,
137 },
138 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300139 .desc = "Cumulate child hist entries",
Namhyung Kim0506aec2014-05-23 18:04:42 +0900140 .func = test__hists_cumulate,
141 },
142 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300143 .desc = "Track with sched_switch",
Adrian Hunterd44bc552014-08-15 22:08:36 +0300144 .func = test__switch_tracking,
145 },
146 {
Arnaldo Carvalho de Melo1b853372014-09-03 18:02:59 -0300147 .desc = "Filter fds with revents mask in a fdarray",
148 .func = test__fdarray__filter,
Arnaldo Carvalho de Melo54dbfae2014-08-12 23:34:06 -0300149 },
150 {
Arnaldo Carvalho de Melo1b853372014-09-03 18:02:59 -0300151 .desc = "Add fd to a fdarray, making it autogrow",
152 .func = test__fdarray__add,
Arnaldo Carvalho de Melo9ae28032014-08-18 16:49:00 -0300153 },
154 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300155 .desc = "kmod_path__parse",
Jiri Olsa3c8a67f2015-02-05 15:40:25 +0100156 .func = test__kmod_path__parse,
157 },
158 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300159 .desc = "Thread map",
Jiri Olsa134aa442015-06-26 11:29:08 +0200160 .func = test__thread_map,
161 },
162 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300163 .desc = "LLVM search and compile",
Wang Nan9bc898c2015-07-08 10:04:02 +0000164 .func = test__llvm,
Wang Nane8c6d502015-11-17 08:32:48 +0000165 .subtest = {
166 .skip_if_fail = true,
167 .get_nr = test__llvm_subtest_get_nr,
168 .get_desc = test__llvm_subtest_get_desc,
169 },
Wang Nan9bc898c2015-07-08 10:04:02 +0000170 },
171 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300172 .desc = "Session topology",
Kan Liangc84974e2015-09-04 04:58:31 -0400173 .func = test_session_topology,
174 },
175 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300176 .desc = "BPF filter",
Wang Nanba1fae42015-11-06 13:49:43 +0000177 .func = test__bpf,
Wang Nan77a0cf62015-11-17 08:32:49 +0000178 .subtest = {
179 .skip_if_fail = true,
180 .get_nr = test__bpf_subtest_get_nr,
181 .get_desc = test__bpf_subtest_get_desc,
182 },
Wang Nanba1fae42015-11-06 13:49:43 +0000183 },
184 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300185 .desc = "Synthesize thread map",
Jiri Olsa99471c92015-10-25 15:51:20 +0100186 .func = test__thread_map_synthesize,
187 },
188 {
Jiri Olsa38af91f2016-12-12 11:35:41 +0100189 .desc = "Remove thread map",
190 .func = test__thread_map_remove,
191 },
192 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300193 .desc = "Synthesize cpu map",
Jiri Olsa6c872902015-10-25 15:51:24 +0100194 .func = test__cpu_map_synthesize,
195 },
196 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300197 .desc = "Synthesize stat config",
Jiri Olsa67424342015-10-25 15:51:28 +0100198 .func = test__synthesize_stat_config,
199 },
200 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300201 .desc = "Synthesize stat",
Jiri Olsa5796f8f2015-10-25 15:51:31 +0100202 .func = test__synthesize_stat,
203 },
204 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300205 .desc = "Synthesize stat round",
Jiri Olsad4c22592015-10-25 15:51:34 +0100206 .func = test__synthesize_stat_round,
207 },
208 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300209 .desc = "Synthesize attr update",
Jiri Olsaa6e52812015-10-25 15:51:37 +0100210 .func = test__event_update,
211 },
212 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300213 .desc = "Event times",
Jiri Olsab31d6602016-03-24 13:52:20 +0100214 .func = test__event_times,
215 },
216 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300217 .desc = "Read backward ring buffer",
Wang Nanee747012016-05-09 01:47:51 +0000218 .func = test__backward_ring_buffer,
219 },
220 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300221 .desc = "Print cpu map",
Jiri Olsaa24020e2016-06-28 13:29:04 +0200222 .func = test__cpu_map_print,
223 },
224 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300225 .desc = "Probe SDT events",
Masami Hiramatsu8e5dc842016-07-12 19:06:05 +0900226 .func = test__sdt_event,
227 },
228 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300229 .desc = "is_printable_array",
Jiri Olsa988dd772016-07-16 18:11:20 +0200230 .func = test__is_printable_array,
231 },
232 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300233 .desc = "Print bitmap",
Jiri Olsaff3e33b2016-08-01 20:02:32 +0200234 .func = test__bitmap_print,
235 },
236 {
Arnaldo Carvalho de Melo030910c2016-11-29 12:38:14 -0300237 .desc = "perf hooks",
Wang Nana0748652016-11-26 07:03:28 +0000238 .func = test__perf_hooks,
239 },
240 {
Wang Nan00b86692016-11-26 07:03:34 +0000241 .desc = "builtin clang support",
242 .func = test__clang,
243 .subtest = {
244 .skip_if_fail = true,
245 .get_nr = test__clang_subtest_get_nr,
246 .get_desc = test__clang_subtest_get_desc,
247 }
248 },
249 {
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300250 .func = NULL,
251 },
252};
253
Matt Fleming31b67532015-10-05 15:40:19 +0100254static struct test *tests[] = {
255 generic_tests,
256 arch_tests,
257};
258
Matt Fleminge8210ce2015-09-05 20:02:20 +0100259static bool perf_test__matches(struct test *test, int curr, int argc, const char *argv[])
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200260{
261 int i;
262
263 if (argc == 0)
264 return true;
265
266 for (i = 0; i < argc; ++i) {
267 char *end;
268 long nr = strtoul(argv[i], &end, 10);
269
270 if (*end == '\0') {
271 if (nr == curr + 1)
272 return true;
273 continue;
274 }
275
Arnaldo Carvalho de Melo345c99a2015-11-06 17:03:38 -0300276 if (strcasestr(test->desc, argv[i]))
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200277 return true;
278 }
279
280 return false;
281}
282
Arnaldo Carvalho de Melo721a1f52015-11-19 12:01:48 -0300283static int run_test(struct test *test, int subtest)
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200284{
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200285 int status, err = -1, child = dont_fork ? 0 : fork();
Masami Hiramatsuba3dfff2014-08-14 02:22:45 +0000286 char sbuf[STRERR_BUFSIZE];
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200287
288 if (child < 0) {
Masami Hiramatsuba3dfff2014-08-14 02:22:45 +0000289 pr_err("failed to fork test: %s\n",
Arnaldo Carvalho de Meloc8b5f2c2016-07-06 11:56:20 -0300290 str_error_r(errno, sbuf, sizeof(sbuf)));
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200291 return -1;
292 }
293
294 if (!child) {
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200295 if (!dont_fork) {
296 pr_debug("test child forked, pid %d\n", getpid());
Wang Nan5bcf2fe2015-11-17 08:32:50 +0000297
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200298 if (!verbose) {
299 int nullfd = open("/dev/null", O_WRONLY);
300
301 if (nullfd >= 0) {
302 close(STDERR_FILENO);
303 close(STDOUT_FILENO);
304
305 dup2(nullfd, STDOUT_FILENO);
306 dup2(STDOUT_FILENO, STDERR_FILENO);
307 close(nullfd);
308 }
309 } else {
310 signal(SIGSEGV, sighandler_dump_stack);
311 signal(SIGFPE, sighandler_dump_stack);
Wang Nan5bcf2fe2015-11-17 08:32:50 +0000312 }
313 }
314
Arnaldo Carvalho de Melo721a1f52015-11-19 12:01:48 -0300315 err = test->func(subtest);
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200316 if (!dont_fork)
317 exit(err);
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200318 }
319
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200320 if (!dont_fork) {
321 wait(&status);
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200322
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200323 if (WIFEXITED(status)) {
324 err = (signed char)WEXITSTATUS(status);
325 pr_debug("test child finished with %d\n", err);
326 } else if (WIFSIGNALED(status)) {
327 err = -1;
328 pr_debug("test child interrupted\n");
329 }
Jiri Olsa0d8a5fa2014-05-10 17:22:30 +0200330 }
331
332 return err;
333}
334
Matt Fleming31b67532015-10-05 15:40:19 +0100335#define for_each_test(j, t) \
336 for (j = 0; j < ARRAY_SIZE(tests); j++) \
337 for (t = &tests[j][0]; t->func; t++)
Matt Fleminge8210ce2015-09-05 20:02:20 +0100338
Wang Nane8c6d502015-11-17 08:32:48 +0000339static int test_and_print(struct test *t, bool force_skip, int subtest)
340{
341 int err;
342
343 if (!force_skip) {
344 pr_debug("\n--- start ---\n");
345 err = run_test(t, subtest);
346 pr_debug("---- end ----\n");
347 } else {
348 pr_debug("\n--- force skipped ---\n");
349 err = TEST_SKIP;
350 }
351
352 if (!t->subtest.get_nr)
353 pr_debug("%s:", t->desc);
354 else
355 pr_debug("%s subtest %d:", t->desc, subtest);
356
357 switch (err) {
358 case TEST_OK:
359 pr_info(" Ok\n");
360 break;
361 case TEST_SKIP:
362 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
363 break;
364 case TEST_FAIL:
365 default:
366 color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
367 break;
368 }
369
370 return err;
371}
372
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300373static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300374{
Matt Fleminge8210ce2015-09-05 20:02:20 +0100375 struct test *t;
Matt Fleming31b67532015-10-05 15:40:19 +0100376 unsigned int j;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300377 int i = 0;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200378 int width = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300379
Matt Fleming31b67532015-10-05 15:40:19 +0100380 for_each_test(j, t) {
Matt Fleminge8210ce2015-09-05 20:02:20 +0100381 int len = strlen(t->desc);
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200382
383 if (width < len)
384 width = len;
Arnaldo Carvalho de Melo9a8e85a2012-10-24 15:44:41 -0200385 }
Jiri Olsa945aea22012-10-30 23:01:43 +0100386
Matt Fleming31b67532015-10-05 15:40:19 +0100387 for_each_test(j, t) {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200388 int curr = i++, err;
389
Matt Fleminge8210ce2015-09-05 20:02:20 +0100390 if (!perf_test__matches(t, curr, argc, argv))
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200391 continue;
392
Matt Fleminge8210ce2015-09-05 20:02:20 +0100393 pr_info("%2d: %-*s:", i, width, t->desc);
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300394
395 if (intlist__find(skiplist, i)) {
396 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
397 continue;
398 }
399
Wang Nane8c6d502015-11-17 08:32:48 +0000400 if (!t->subtest.get_nr) {
401 test_and_print(t, false, -1);
402 } else {
403 int subn = t->subtest.get_nr();
404 /*
405 * minus 2 to align with normal testcases.
406 * For subtest we print additional '.x' in number.
407 * for example:
408 *
409 * 35: Test LLVM searching and compiling :
410 * 35.1: Basic BPF llvm compiling test : Ok
411 */
412 int subw = width > 2 ? width - 2 : width;
413 bool skip = false;
414 int subi;
Jiri Olsaf4c1ea52012-12-19 11:33:39 -0300415
Wang Nane8c6d502015-11-17 08:32:48 +0000416 if (subn <= 0) {
417 color_fprintf(stderr, PERF_COLOR_YELLOW,
418 " Skip (not compiled in)\n");
419 continue;
420 }
421 pr_info("\n");
422
423 for (subi = 0; subi < subn; subi++) {
424 int len = strlen(t->subtest.get_desc(subi));
425
426 if (subw < len)
427 subw = len;
428 }
429
430 for (subi = 0; subi < subn; subi++) {
431 pr_info("%2d.%1d: %-*s:", i, subi + 1, subw,
432 t->subtest.get_desc(subi));
433 err = test_and_print(t, skip, subi);
434 if (err != TEST_OK && t->subtest.skip_if_fail)
435 skip = true;
436 }
Jiri Olsaf4c1ea52012-12-19 11:33:39 -0300437 }
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300438 }
439
440 return 0;
441}
442
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200443static int perf_test__list(int argc, const char **argv)
444{
Matt Fleming31b67532015-10-05 15:40:19 +0100445 unsigned int j;
Matt Fleminge8210ce2015-09-05 20:02:20 +0100446 struct test *t;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200447 int i = 0;
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300448
Matt Fleming31b67532015-10-05 15:40:19 +0100449 for_each_test(j, t) {
Matt Fleminge8210ce2015-09-05 20:02:20 +0100450 if (argc > 1 && !strstr(t->desc, argv[1]))
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200451 continue;
452
Matt Fleminge8210ce2015-09-05 20:02:20 +0100453 pr_info("%2d: %s\n", ++i, t->desc);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200454 }
455
456 return 0;
457}
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300458
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300459int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300460{
Yunlong Song1f9975f2015-03-18 21:35:55 +0800461 const char *test_usage[] = {
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200462 "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
463 NULL,
464 };
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300465 const char *skip = NULL;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200466 const struct option test_options[] = {
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300467 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
Namhyung Kimc30ab8a2012-01-08 02:25:26 +0900468 OPT_INCR('v', "verbose", &verbose,
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200469 "be more verbose (show symbol address, etc)"),
Jiri Olsa7fa9b8f2016-06-28 13:29:01 +0200470 OPT_BOOLEAN('F', "dont-fork", &dont_fork,
471 "Do not fork for testcase"),
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200472 OPT_END()
473 };
Yunlong Song1f9975f2015-03-18 21:35:55 +0800474 const char * const test_subcommands[] = { "list", NULL };
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300475 struct intlist *skiplist = NULL;
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -0300476 int ret = hists__init();
477
478 if (ret < 0)
479 return ret;
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200480
Yunlong Song1f9975f2015-03-18 21:35:55 +0800481 argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
Arnaldo Carvalho de Meloe60770a2011-11-29 12:52:07 -0200482 if (argc >= 1 && !strcmp(argv[0], "list"))
483 return perf_test__list(argc, argv);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300484
485 symbol_conf.priv_size = sizeof(int);
486 symbol_conf.sort_by_name = true;
487 symbol_conf.try_vmlinux_path = true;
488
Namhyung Kim0a7e6d12014-08-12 15:40:45 +0900489 if (symbol__init(NULL) < 0)
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300490 return -1;
491
Arnaldo Carvalho de Melo2ae82872013-01-24 16:22:55 -0300492 if (skip != NULL)
493 skiplist = intlist__new(skip);
494
495 return __cmd_test(argc, argv, skiplist);
Arnaldo Carvalho de Melo1c6a8002010-04-29 18:58:32 -0300496}