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 | }, |
| 118 | { |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 119 | .func = NULL, |
| 120 | }, |
| 121 | }; |
| 122 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 123 | static bool perf_test__matches(int curr, int argc, const char *argv[]) |
| 124 | { |
| 125 | int i; |
| 126 | |
| 127 | if (argc == 0) |
| 128 | return true; |
| 129 | |
| 130 | for (i = 0; i < argc; ++i) { |
| 131 | char *end; |
| 132 | long nr = strtoul(argv[i], &end, 10); |
| 133 | |
| 134 | if (*end == '\0') { |
| 135 | if (nr == curr + 1) |
| 136 | return true; |
| 137 | continue; |
| 138 | } |
| 139 | |
| 140 | if (strstr(tests[curr].desc, argv[i])) |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | return false; |
| 145 | } |
| 146 | |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 147 | 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] | 148 | { |
| 149 | int i = 0; |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 150 | int width = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 151 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 152 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 153 | int len = strlen(tests[i].desc); |
| 154 | |
| 155 | if (width < len) |
| 156 | width = len; |
| 157 | ++i; |
| 158 | } |
Jiri Olsa | 945aea2 | 2012-10-30 23:01:43 +0100 | [diff] [blame] | 159 | |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 160 | i = 0; |
| 161 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 162 | int curr = i++, err; |
| 163 | |
| 164 | if (!perf_test__matches(curr, argc, argv)) |
| 165 | continue; |
| 166 | |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 167 | pr_info("%2d: %-*s:", i, width, tests[curr].desc); |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 168 | |
| 169 | if (intlist__find(skiplist, i)) { |
| 170 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); |
| 171 | continue; |
| 172 | } |
| 173 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 174 | pr_debug("\n--- start ---\n"); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 175 | err = tests[curr].func(); |
| 176 | pr_debug("---- end ----\n%s:", tests[curr].desc); |
Jiri Olsa | f4c1ea5 | 2012-12-19 11:33:39 -0300 | [diff] [blame] | 177 | |
| 178 | switch (err) { |
| 179 | case TEST_OK: |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 180 | pr_info(" Ok\n"); |
Jiri Olsa | f4c1ea5 | 2012-12-19 11:33:39 -0300 | [diff] [blame] | 181 | break; |
| 182 | case TEST_SKIP: |
| 183 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); |
| 184 | break; |
| 185 | case TEST_FAIL: |
| 186 | default: |
| 187 | color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); |
| 188 | break; |
| 189 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 195 | static int perf_test__list(int argc, const char **argv) |
| 196 | { |
| 197 | int i = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 198 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 199 | while (tests[i].func) { |
| 200 | int curr = i++; |
| 201 | |
| 202 | if (argc > 1 && !strstr(tests[curr].desc, argv[1])) |
| 203 | continue; |
| 204 | |
| 205 | pr_info("%2d: %s\n", i, tests[curr].desc); |
| 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 210 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 211 | 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] | 212 | { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 213 | const char * const test_usage[] = { |
| 214 | "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", |
| 215 | NULL, |
| 216 | }; |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 217 | const char *skip = NULL; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 218 | const struct option test_options[] = { |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 219 | OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), |
Namhyung Kim | c30ab8a | 2012-01-08 02:25:26 +0900 | [diff] [blame] | 220 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 221 | "be more verbose (show symbol address, etc)"), |
| 222 | OPT_END() |
| 223 | }; |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 224 | struct intlist *skiplist = NULL; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 225 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 226 | argc = parse_options(argc, argv, test_options, test_usage, 0); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 227 | if (argc >= 1 && !strcmp(argv[0], "list")) |
| 228 | return perf_test__list(argc, argv); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 229 | |
| 230 | symbol_conf.priv_size = sizeof(int); |
| 231 | symbol_conf.sort_by_name = true; |
| 232 | symbol_conf.try_vmlinux_path = true; |
| 233 | |
| 234 | if (symbol__init() < 0) |
| 235 | return -1; |
| 236 | |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 237 | if (skip != NULL) |
| 238 | skiplist = intlist__new(skip); |
| 239 | |
| 240 | return __cmd_test(argc, argv, skiplist); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 241 | } |