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" |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 7 | #include "intlist.h" |
Jiri Olsa | 0a4e1ae | 2012-11-10 01:46:41 +0100 | [diff] [blame] | 8 | #include "tests.h" |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 9 | #include "debug.h" |
| 10 | #include "color.h" |
| 11 | #include "parse-options.h" |
| 12 | #include "symbol.h" |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 13 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 14 | static struct test { |
| 15 | const char *desc; |
| 16 | int (*func)(void); |
| 17 | } tests[] = { |
| 18 | { |
| 19 | .desc = "vmlinux symtab matches kallsyms", |
| 20 | .func = test__vmlinux_matches_kallsyms, |
| 21 | }, |
| 22 | { |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 23 | .desc = "detect open syscall event", |
| 24 | .func = test__open_syscall_event, |
| 25 | }, |
| 26 | { |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 27 | .desc = "detect open syscall event on all cpus", |
| 28 | .func = test__open_syscall_event_on_all_cpus, |
| 29 | }, |
| 30 | { |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 31 | .desc = "read samples using the mmap interface", |
| 32 | .func = test__basic_mmap, |
| 33 | }, |
| 34 | { |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 35 | .desc = "parse events tests", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 36 | .func = test__parse_events, |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 37 | }, |
Peter Zijlstra | 08aa0d1 | 2011-11-21 14:42:47 +0100 | [diff] [blame] | 38 | #if defined(__x86_64__) || defined(__i386__) |
| 39 | { |
| 40 | .desc = "x86 rdpmc test", |
| 41 | .func = test__rdpmc, |
| 42 | }, |
| 43 | #endif |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 44 | { |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 45 | .desc = "Validate PERF_RECORD_* events & perf_sample fields", |
| 46 | .func = test__PERF_RECORD, |
| 47 | }, |
| 48 | { |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 49 | .desc = "Test perf pmu format parsing", |
Jiri Olsa | cff7f95 | 2012-11-10 01:46:50 +0100 | [diff] [blame] | 50 | .func = test__pmu, |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 51 | }, |
| 52 | { |
Jiri Olsa | f7add55 | 2012-07-22 14:14:40 +0200 | [diff] [blame] | 53 | .desc = "Test dso data interface", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 54 | .func = test__dso_data, |
Jiri Olsa | f7add55 | 2012-07-22 14:14:40 +0200 | [diff] [blame] | 55 | }, |
| 56 | { |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 57 | .desc = "roundtrip evsel->name check", |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 58 | .func = test__perf_evsel__roundtrip_name_test, |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 59 | }, |
| 60 | { |
Arnaldo Carvalho de Melo | 6a6cd11 | 2012-09-18 11:56:28 -0300 | [diff] [blame] | 61 | .desc = "Check parsing of sched tracepoints fields", |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 62 | .func = test__perf_evsel__tp_sched_test, |
Arnaldo Carvalho de Melo | 6a6cd11 | 2012-09-18 11:56:28 -0300 | [diff] [blame] | 63 | }, |
| 64 | { |
Arnaldo Carvalho de Melo | eb2f270 | 2012-09-26 13:23:10 -0300 | [diff] [blame] | 65 | .desc = "Generate and check syscalls:sys_enter_open event fields", |
| 66 | .func = test__syscall_open_tp_fields, |
| 67 | }, |
| 68 | { |
Jiri Olsa | d898b24 | 2012-10-30 23:02:05 +0100 | [diff] [blame] | 69 | .desc = "struct perf_event_attr setup", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 70 | .func = test__attr, |
Jiri Olsa | d898b24 | 2012-10-30 23:02:05 +0100 | [diff] [blame] | 71 | }, |
| 72 | { |
Arnaldo Carvalho de Melo | ffcbaa1 | 2013-05-23 12:08:38 +0200 | [diff] [blame] | 73 | .desc = "Test matching and linking multiple hists", |
Namhyung Kim | f8ebb0c | 2012-12-10 17:29:57 +0900 | [diff] [blame] | 74 | .func = test__hists_link, |
| 75 | }, |
| 76 | { |
Arnaldo Carvalho de Melo | 54359d3 | 2012-12-14 13:06:13 -0300 | [diff] [blame] | 77 | .desc = "Try 'use perf' in python, checking link problems", |
| 78 | .func = test__python_use, |
| 79 | }, |
| 80 | { |
Jiri Olsa | 5a6bef4 | 2013-03-10 19:41:10 +0100 | [diff] [blame] | 81 | .desc = "Test breakpoint overflow signal handler", |
| 82 | .func = test__bp_signal, |
| 83 | }, |
| 84 | { |
Jiri Olsa | 06933e3 | 2013-03-10 19:41:11 +0100 | [diff] [blame] | 85 | .desc = "Test breakpoint overflow sampling", |
| 86 | .func = test__bp_signal_overflow, |
| 87 | }, |
| 88 | { |
Namhyung Kim | d723a55 | 2013-03-15 14:58:11 +0900 | [diff] [blame] | 89 | .desc = "Test number of exit event of a simple workload", |
| 90 | .func = test__task_exit, |
| 91 | }, |
| 92 | { |
Namhyung Kim | bc96b36 | 2013-03-18 11:41:47 +0900 | [diff] [blame] | 93 | .desc = "Test software clock events have valid period values", |
| 94 | .func = test__sw_clock_freq, |
| 95 | }, |
Adrian Hunter | 3bd5a5f | 2013-06-28 16:22:19 +0300 | [diff] [blame] | 96 | #if defined(__x86_64__) || defined(__i386__) |
| 97 | { |
| 98 | .desc = "Test converting perf time to TSC", |
| 99 | .func = test__perf_time_to_tsc, |
| 100 | }, |
| 101 | #endif |
Namhyung Kim | bc96b36 | 2013-03-18 11:41:47 +0900 | [diff] [blame] | 102 | { |
Adrian Hunter | b55ae0a | 2013-08-07 14:38:45 +0300 | [diff] [blame] | 103 | .desc = "Test object code reading", |
| 104 | .func = test__code_reading, |
| 105 | }, |
| 106 | { |
Adrian Hunter | 045f8cd8 | 2013-08-27 11:23:13 +0300 | [diff] [blame] | 107 | .desc = "Test sample parsing", |
| 108 | .func = test__sample_parsing, |
| 109 | }, |
| 110 | { |
Adrian Hunter | 395c307 | 2013-08-31 21:50:53 +0300 | [diff] [blame] | 111 | .desc = "Test using a dummy software event to keep tracking", |
| 112 | .func = test__keep_tracking, |
| 113 | }, |
| 114 | { |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 115 | .desc = "Test parsing with no sample_id_all bit set", |
| 116 | .func = test__parse_no_sample_id_all, |
| 117 | }, |
Jiri Olsa | aa16b81 | 2014-01-07 13:47:22 +0100 | [diff] [blame] | 118 | #if defined(__x86_64__) || defined(__i386__) |
Jiri Olsa | 9ff125d | 2014-01-07 13:47:28 +0100 | [diff] [blame] | 119 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
Jiri Olsa | aa16b81 | 2014-01-07 13:47:22 +0100 | [diff] [blame] | 120 | { |
| 121 | .desc = "Test dwarf unwind", |
| 122 | .func = test__dwarf_unwind, |
| 123 | }, |
| 124 | #endif |
| 125 | #endif |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 126 | { |
Namhyung Kim | 3c3cfd9 | 2014-04-25 12:28:14 +0900 | [diff] [blame] | 127 | .desc = "Test filtering hist entries", |
| 128 | .func = test__hists_filter, |
| 129 | }, |
| 130 | { |
Jiri Olsa | 4e85edf | 2014-03-05 17:20:31 +0100 | [diff] [blame^] | 131 | .desc = "Test mmap thread lookup", |
| 132 | .func = test__mmap_thread_lookup, |
| 133 | }, |
| 134 | { |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 135 | .func = NULL, |
| 136 | }, |
| 137 | }; |
| 138 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 139 | static bool perf_test__matches(int curr, int argc, const char *argv[]) |
| 140 | { |
| 141 | int i; |
| 142 | |
| 143 | if (argc == 0) |
| 144 | return true; |
| 145 | |
| 146 | for (i = 0; i < argc; ++i) { |
| 147 | char *end; |
| 148 | long nr = strtoul(argv[i], &end, 10); |
| 149 | |
| 150 | if (*end == '\0') { |
| 151 | if (nr == curr + 1) |
| 152 | return true; |
| 153 | continue; |
| 154 | } |
| 155 | |
| 156 | if (strstr(tests[curr].desc, argv[i])) |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | return false; |
| 161 | } |
| 162 | |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 163 | static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 164 | { |
| 165 | int i = 0; |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 166 | int width = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 167 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 168 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 169 | int len = strlen(tests[i].desc); |
| 170 | |
| 171 | if (width < len) |
| 172 | width = len; |
| 173 | ++i; |
| 174 | } |
Jiri Olsa | 945aea2 | 2012-10-30 23:01:43 +0100 | [diff] [blame] | 175 | |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 176 | i = 0; |
| 177 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 178 | int curr = i++, err; |
| 179 | |
| 180 | if (!perf_test__matches(curr, argc, argv)) |
| 181 | continue; |
| 182 | |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 183 | pr_info("%2d: %-*s:", i, width, tests[curr].desc); |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 184 | |
| 185 | if (intlist__find(skiplist, i)) { |
| 186 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); |
| 187 | continue; |
| 188 | } |
| 189 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 190 | pr_debug("\n--- start ---\n"); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 191 | err = tests[curr].func(); |
| 192 | pr_debug("---- end ----\n%s:", tests[curr].desc); |
Jiri Olsa | f4c1ea5 | 2012-12-19 11:33:39 -0300 | [diff] [blame] | 193 | |
| 194 | switch (err) { |
| 195 | case TEST_OK: |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 196 | pr_info(" Ok\n"); |
Jiri Olsa | f4c1ea5 | 2012-12-19 11:33:39 -0300 | [diff] [blame] | 197 | break; |
| 198 | case TEST_SKIP: |
| 199 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); |
| 200 | break; |
| 201 | case TEST_FAIL: |
| 202 | default: |
| 203 | color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); |
| 204 | break; |
| 205 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 211 | static int perf_test__list(int argc, const char **argv) |
| 212 | { |
| 213 | int i = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 214 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 215 | while (tests[i].func) { |
| 216 | int curr = i++; |
| 217 | |
| 218 | if (argc > 1 && !strstr(tests[curr].desc, argv[1])) |
| 219 | continue; |
| 220 | |
| 221 | pr_info("%2d: %s\n", i, tests[curr].desc); |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 226 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 227 | 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] | 228 | { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 229 | const char * const test_usage[] = { |
| 230 | "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", |
| 231 | NULL, |
| 232 | }; |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 233 | const char *skip = NULL; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 234 | const struct option test_options[] = { |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 235 | OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), |
Namhyung Kim | c30ab8a | 2012-01-08 02:25:26 +0900 | [diff] [blame] | 236 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 237 | "be more verbose (show symbol address, etc)"), |
| 238 | OPT_END() |
| 239 | }; |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 240 | struct intlist *skiplist = NULL; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 241 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 242 | argc = parse_options(argc, argv, test_options, test_usage, 0); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 243 | if (argc >= 1 && !strcmp(argv[0], "list")) |
| 244 | return perf_test__list(argc, argv); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 245 | |
| 246 | symbol_conf.priv_size = sizeof(int); |
| 247 | symbol_conf.sort_by_name = true; |
| 248 | symbol_conf.try_vmlinux_path = true; |
| 249 | |
| 250 | if (symbol__init() < 0) |
| 251 | return -1; |
| 252 | |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 253 | if (skip != NULL) |
| 254 | skiplist = intlist__new(skip); |
| 255 | |
| 256 | return __cmd_test(argc, argv, skiplist); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 257 | } |