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