Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1 | /* |
| 2 | * builtin-test.c |
| 3 | * |
| 4 | * Builtin regression testing command: ever growing number of sanity tests |
| 5 | */ |
| 6 | #include "builtin.h" |
Jiri Olsa | 0a4e1ae | 2012-11-10 01:46:41 +0100 | [diff] [blame] | 7 | #include "tests.h" |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 8 | #include "debug.h" |
| 9 | #include "color.h" |
| 10 | #include "parse-options.h" |
| 11 | #include "symbol.h" |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 12 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 13 | static struct test { |
| 14 | const char *desc; |
| 15 | int (*func)(void); |
| 16 | } tests[] = { |
| 17 | { |
| 18 | .desc = "vmlinux symtab matches kallsyms", |
| 19 | .func = test__vmlinux_matches_kallsyms, |
| 20 | }, |
| 21 | { |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 22 | .desc = "detect open syscall event", |
| 23 | .func = test__open_syscall_event, |
| 24 | }, |
| 25 | { |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 26 | .desc = "detect open syscall event on all cpus", |
| 27 | .func = test__open_syscall_event_on_all_cpus, |
| 28 | }, |
| 29 | { |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 30 | .desc = "read samples using the mmap interface", |
| 31 | .func = test__basic_mmap, |
| 32 | }, |
| 33 | { |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 34 | .desc = "parse events tests", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 35 | .func = test__parse_events, |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 36 | }, |
Peter Zijlstra | 08aa0d1 | 2011-11-21 14:42:47 +0100 | [diff] [blame] | 37 | #if defined(__x86_64__) || defined(__i386__) |
| 38 | { |
| 39 | .desc = "x86 rdpmc test", |
| 40 | .func = test__rdpmc, |
| 41 | }, |
| 42 | #endif |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 43 | { |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 44 | .desc = "Validate PERF_RECORD_* events & perf_sample fields", |
| 45 | .func = test__PERF_RECORD, |
| 46 | }, |
| 47 | { |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 48 | .desc = "Test perf pmu format parsing", |
Jiri Olsa | cff7f95 | 2012-11-10 01:46:50 +0100 | [diff] [blame] | 49 | .func = test__pmu, |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 50 | }, |
| 51 | { |
Jiri Olsa | f7add55 | 2012-07-22 14:14:40 +0200 | [diff] [blame] | 52 | .desc = "Test dso data interface", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 53 | .func = test__dso_data, |
Jiri Olsa | f7add55 | 2012-07-22 14:14:40 +0200 | [diff] [blame] | 54 | }, |
| 55 | { |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 56 | .desc = "roundtrip evsel->name check", |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 57 | .func = test__perf_evsel__roundtrip_name_test, |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 58 | }, |
| 59 | { |
Arnaldo Carvalho de Melo | 6a6cd11 | 2012-09-18 11:56:28 -0300 | [diff] [blame] | 60 | .desc = "Check parsing of sched tracepoints fields", |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 61 | .func = test__perf_evsel__tp_sched_test, |
Arnaldo Carvalho de Melo | 6a6cd11 | 2012-09-18 11:56:28 -0300 | [diff] [blame] | 62 | }, |
| 63 | { |
Arnaldo Carvalho de Melo | eb2f270 | 2012-09-26 13:23:10 -0300 | [diff] [blame] | 64 | .desc = "Generate and check syscalls:sys_enter_open event fields", |
| 65 | .func = test__syscall_open_tp_fields, |
| 66 | }, |
| 67 | { |
Jiri Olsa | d898b24 | 2012-10-30 23:02:05 +0100 | [diff] [blame] | 68 | .desc = "struct perf_event_attr setup", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 69 | .func = test__attr, |
Jiri Olsa | d898b24 | 2012-10-30 23:02:05 +0100 | [diff] [blame] | 70 | }, |
| 71 | { |
Namhyung Kim | f8ebb0c | 2012-12-10 17:29:57 +0900 | [diff] [blame^] | 72 | .desc = "Test matching and linking mutliple hists", |
| 73 | .func = test__hists_link, |
| 74 | }, |
| 75 | { |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 76 | .func = NULL, |
| 77 | }, |
| 78 | }; |
| 79 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 80 | static bool perf_test__matches(int curr, int argc, const char *argv[]) |
| 81 | { |
| 82 | int i; |
| 83 | |
| 84 | if (argc == 0) |
| 85 | return true; |
| 86 | |
| 87 | for (i = 0; i < argc; ++i) { |
| 88 | char *end; |
| 89 | long nr = strtoul(argv[i], &end, 10); |
| 90 | |
| 91 | if (*end == '\0') { |
| 92 | if (nr == curr + 1) |
| 93 | return true; |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | if (strstr(tests[curr].desc, argv[i])) |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | static int __cmd_test(int argc, const char *argv[]) |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 105 | { |
| 106 | int i = 0; |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 107 | int width = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 108 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 109 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 110 | int len = strlen(tests[i].desc); |
| 111 | |
| 112 | if (width < len) |
| 113 | width = len; |
| 114 | ++i; |
| 115 | } |
Jiri Olsa | 945aea2 | 2012-10-30 23:01:43 +0100 | [diff] [blame] | 116 | |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 117 | i = 0; |
| 118 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 119 | int curr = i++, err; |
| 120 | |
| 121 | if (!perf_test__matches(curr, argc, argv)) |
| 122 | continue; |
| 123 | |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 124 | pr_info("%2d: %-*s:", i, width, tests[curr].desc); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 125 | pr_debug("\n--- start ---\n"); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 126 | err = tests[curr].func(); |
| 127 | pr_debug("---- end ----\n%s:", tests[curr].desc); |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 128 | if (err) |
| 129 | color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); |
| 130 | else |
| 131 | pr_info(" Ok\n"); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 137 | static int perf_test__list(int argc, const char **argv) |
| 138 | { |
| 139 | int i = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 140 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 141 | while (tests[i].func) { |
| 142 | int curr = i++; |
| 143 | |
| 144 | if (argc > 1 && !strstr(tests[curr].desc, argv[1])) |
| 145 | continue; |
| 146 | |
| 147 | pr_info("%2d: %s\n", i, tests[curr].desc); |
| 148 | } |
| 149 | |
| 150 | return 0; |
| 151 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 152 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 153 | int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused) |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 154 | { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 155 | const char * const test_usage[] = { |
| 156 | "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", |
| 157 | NULL, |
| 158 | }; |
| 159 | const struct option test_options[] = { |
Namhyung Kim | c30ab8a | 2012-01-08 02:25:26 +0900 | [diff] [blame] | 160 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 161 | "be more verbose (show symbol address, etc)"), |
| 162 | OPT_END() |
| 163 | }; |
| 164 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 165 | argc = parse_options(argc, argv, test_options, test_usage, 0); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 166 | if (argc >= 1 && !strcmp(argv[0], "list")) |
| 167 | return perf_test__list(argc, argv); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 168 | |
| 169 | symbol_conf.priv_size = sizeof(int); |
| 170 | symbol_conf.sort_by_name = true; |
| 171 | symbol_conf.try_vmlinux_path = true; |
| 172 | |
| 173 | if (symbol__init() < 0) |
| 174 | return -1; |
| 175 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 176 | return __cmd_test(argc, argv); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 177 | } |