Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 2 | /* |
| 3 | * builtin-test.c |
| 4 | * |
| 5 | * Builtin regression testing command: ever growing number of sanity tests |
| 6 | */ |
Arnaldo Carvalho de Melo | c23c2a0 | 2017-09-11 10:50:26 -0300 | [diff] [blame] | 7 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 8 | #include <errno.h> |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 9 | #include <unistd.h> |
| 10 | #include <string.h> |
Arnaldo Carvalho de Melo | f2a39fe | 2019-08-30 14:45:20 -0300 | [diff] [blame] | 11 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 12 | #include <sys/types.h> |
| 13 | #include <dirent.h> |
Arnaldo Carvalho de Melo | 4208735 | 2017-04-19 19:06:30 -0300 | [diff] [blame] | 14 | #include <sys/wait.h> |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 15 | #include <sys/stat.h> |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 16 | #include "builtin.h" |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 17 | #include "hist.h" |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 18 | #include "intlist.h" |
Jiri Olsa | 0a4e1ae | 2012-11-10 01:46:41 +0100 | [diff] [blame] | 19 | #include "tests.h" |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 20 | #include "debug.h" |
| 21 | #include "color.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 22 | #include <subcmd/parse-options.h> |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 23 | #include "string2.h" |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 24 | #include "symbol.h" |
Arnaldo Carvalho de Melo | d3280ce | 2019-07-09 16:27:01 -0300 | [diff] [blame] | 25 | #include "util/rlimit.h" |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 26 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | 3ca43b6 | 2019-06-26 12:06:20 -0300 | [diff] [blame] | 27 | #include <linux/string.h> |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 28 | #include <subcmd/exec-cmd.h> |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 29 | |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 30 | static bool dont_fork; |
| 31 | |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 32 | struct test __weak arch_tests[] = { |
| 33 | { |
| 34 | .func = NULL, |
| 35 | }, |
| 36 | }; |
| 37 | |
| 38 | static struct test generic_tests[] = { |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 39 | { |
| 40 | .desc = "vmlinux symtab matches kallsyms", |
| 41 | .func = test__vmlinux_matches_kallsyms, |
| 42 | }, |
| 43 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 44 | .desc = "Detect openat syscall event", |
Riku Voipio | 43f322b | 2015-04-16 16:52:53 +0300 | [diff] [blame] | 45 | .func = test__openat_syscall_event, |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 46 | }, |
| 47 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 48 | .desc = "Detect openat syscall event on all cpus", |
Riku Voipio | 43f322b | 2015-04-16 16:52:53 +0300 | [diff] [blame] | 49 | .func = test__openat_syscall_event_on_all_cpus, |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 50 | }, |
| 51 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 52 | .desc = "Read samples using the mmap interface", |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 53 | .func = test__basic_mmap, |
| 54 | }, |
| 55 | { |
Andi Kleen | 3067eaa | 2017-08-16 15:21:56 -0700 | [diff] [blame] | 56 | .desc = "Test data source output", |
| 57 | .func = test__mem, |
| 58 | }, |
| 59 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 60 | .desc = "Parse event definition strings", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 61 | .func = test__parse_events, |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 62 | }, |
| 63 | { |
Andi Kleen | 0751673 | 2017-03-20 13:17:05 -0700 | [diff] [blame] | 64 | .desc = "Simple expression parser", |
| 65 | .func = test__expr, |
| 66 | }, |
| 67 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 68 | .desc = "PERF_RECORD_* events & perf_sample fields", |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 69 | .func = test__PERF_RECORD, |
| 70 | }, |
| 71 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 72 | .desc = "Parse perf pmu format", |
Jiri Olsa | cff7f95 | 2012-11-10 01:46:50 +0100 | [diff] [blame] | 73 | .func = test__pmu, |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 74 | }, |
| 75 | { |
John Garry | a6c925f | 2020-03-17 19:02:16 +0800 | [diff] [blame] | 76 | .desc = "PMU events", |
| 77 | .func = test__pmu_events, |
Ian Rogers | 06392aa | 2020-05-13 14:29:33 -0700 | [diff] [blame] | 78 | .subtest = { |
| 79 | .skip_if_fail = false, |
| 80 | .get_nr = test__pmu_events_subtest_get_nr, |
| 81 | .get_desc = test__pmu_events_subtest_get_desc, |
| 82 | .skip_reason = test__pmu_events_subtest_skip_reason, |
| 83 | }, |
| 84 | |
John Garry | a6c925f | 2020-03-17 19:02:16 +0800 | [diff] [blame] | 85 | }, |
| 86 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 87 | .desc = "DSO data read", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 88 | .func = test__dso_data, |
Jiri Olsa | f7add55 | 2012-07-22 14:14:40 +0200 | [diff] [blame] | 89 | }, |
| 90 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 91 | .desc = "DSO data cache", |
Jiri Olsa | 4ebbcb8 | 2014-05-12 14:43:53 +0200 | [diff] [blame] | 92 | .func = test__dso_data_cache, |
| 93 | }, |
| 94 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 95 | .desc = "DSO data reopen", |
Jiri Olsa | 45dc1bb5 | 2014-05-12 14:50:03 +0200 | [diff] [blame] | 96 | .func = test__dso_data_reopen, |
| 97 | }, |
| 98 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 99 | .desc = "Roundtrip evsel->name", |
Jiri Olsa | cfffae2 | 2012-11-10 01:46:47 +0100 | [diff] [blame] | 100 | .func = test__perf_evsel__roundtrip_name_test, |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 101 | }, |
| 102 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 103 | .desc = "Parse sched tracepoints fields", |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 104 | .func = test__perf_evsel__tp_sched_test, |
Arnaldo Carvalho de Melo | 6a6cd11 | 2012-09-18 11:56:28 -0300 | [diff] [blame] | 105 | }, |
| 106 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 107 | .desc = "syscalls:sys_enter_openat event fields", |
Riku Voipio | 43f322b | 2015-04-16 16:52:53 +0300 | [diff] [blame] | 108 | .func = test__syscall_openat_tp_fields, |
Arnaldo Carvalho de Melo | eb2f270 | 2012-09-26 13:23:10 -0300 | [diff] [blame] | 109 | }, |
| 110 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 111 | .desc = "Setup struct perf_event_attr", |
Jiri Olsa | c81251e | 2012-11-10 01:46:51 +0100 | [diff] [blame] | 112 | .func = test__attr, |
Jiri Olsa | d898b24 | 2012-10-30 23:02:05 +0100 | [diff] [blame] | 113 | }, |
| 114 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 115 | .desc = "Match and link multiple hists", |
Namhyung Kim | f8ebb0c | 2012-12-10 17:29:57 +0900 | [diff] [blame] | 116 | .func = test__hists_link, |
| 117 | }, |
| 118 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 119 | .desc = "'import perf' in python", |
Arnaldo Carvalho de Melo | 54359d3 | 2012-12-14 13:06:13 -0300 | [diff] [blame] | 120 | .func = test__python_use, |
| 121 | }, |
| 122 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 123 | .desc = "Breakpoint overflow signal handler", |
Jiri Olsa | 5a6bef4 | 2013-03-10 19:41:10 +0100 | [diff] [blame] | 124 | .func = test__bp_signal, |
Jiri Olsa | 598762c | 2017-06-01 22:54:50 +0200 | [diff] [blame] | 125 | .is_supported = test__bp_signal_is_supported, |
Jiri Olsa | 5a6bef4 | 2013-03-10 19:41:10 +0100 | [diff] [blame] | 126 | }, |
| 127 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 128 | .desc = "Breakpoint overflow sampling", |
Jiri Olsa | 06933e3 | 2013-03-10 19:41:11 +0100 | [diff] [blame] | 129 | .func = test__bp_signal_overflow, |
Jiri Olsa | 598762c | 2017-06-01 22:54:50 +0200 | [diff] [blame] | 130 | .is_supported = test__bp_signal_is_supported, |
Jiri Olsa | 06933e3 | 2013-03-10 19:41:11 +0100 | [diff] [blame] | 131 | }, |
| 132 | { |
Jiri Olsa | 032db28 | 2018-03-12 14:45:48 +0100 | [diff] [blame] | 133 | .desc = "Breakpoint accounting", |
| 134 | .func = test__bp_accounting, |
Leo Yan | e533ead | 2019-10-18 16:55:30 +0800 | [diff] [blame] | 135 | .is_supported = test__bp_account_is_supported, |
Jiri Olsa | 032db28 | 2018-03-12 14:45:48 +0100 | [diff] [blame] | 136 | }, |
| 137 | { |
Ravi Bangoria | 2e85d59 | 2018-09-12 11:42:29 +0530 | [diff] [blame] | 138 | .desc = "Watchpoint", |
| 139 | .func = test__wp, |
Thomas Richter | 0e24147 | 2018-09-28 12:53:35 +0200 | [diff] [blame] | 140 | .is_supported = test__wp_is_supported, |
Ravi Bangoria | 2e85d59 | 2018-09-12 11:42:29 +0530 | [diff] [blame] | 141 | .subtest = { |
| 142 | .skip_if_fail = false, |
| 143 | .get_nr = test__wp_subtest_get_nr, |
| 144 | .get_desc = test__wp_subtest_get_desc, |
Tommi Rantala | cc3b964 | 2020-10-16 16:16:50 +0300 | [diff] [blame] | 145 | .skip_reason = test__wp_subtest_skip_reason, |
Ravi Bangoria | 2e85d59 | 2018-09-12 11:42:29 +0530 | [diff] [blame] | 146 | }, |
| 147 | }, |
| 148 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 149 | .desc = "Number of exit events of a simple workload", |
Namhyung Kim | d723a55 | 2013-03-15 14:58:11 +0900 | [diff] [blame] | 150 | .func = test__task_exit, |
| 151 | }, |
| 152 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 153 | .desc = "Software clock events period values", |
Namhyung Kim | bc96b36 | 2013-03-18 11:41:47 +0900 | [diff] [blame] | 154 | .func = test__sw_clock_freq, |
| 155 | }, |
| 156 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 157 | .desc = "Object code reading", |
Adrian Hunter | b55ae0a | 2013-08-07 14:38:45 +0300 | [diff] [blame] | 158 | .func = test__code_reading, |
| 159 | }, |
| 160 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 161 | .desc = "Sample parsing", |
Adrian Hunter | 045f8cd8 | 2013-08-27 11:23:13 +0300 | [diff] [blame] | 162 | .func = test__sample_parsing, |
| 163 | }, |
| 164 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 165 | .desc = "Use a dummy software event to keep tracking", |
Adrian Hunter | 395c307 | 2013-08-31 21:50:53 +0300 | [diff] [blame] | 166 | .func = test__keep_tracking, |
| 167 | }, |
| 168 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 169 | .desc = "Parse with no sample_id_all bit set", |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 170 | .func = test__parse_no_sample_id_all, |
| 171 | }, |
| 172 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 173 | .desc = "Filter hist entries", |
Namhyung Kim | 3c3cfd9 | 2014-04-25 12:28:14 +0900 | [diff] [blame] | 174 | .func = test__hists_filter, |
| 175 | }, |
| 176 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 177 | .desc = "Lookup mmap thread", |
Jiri Olsa | 4e85edf | 2014-03-05 17:20:31 +0100 | [diff] [blame] | 178 | .func = test__mmap_thread_lookup, |
| 179 | }, |
| 180 | { |
Arnaldo Carvalho de Melo | 6d38267 | 2019-11-25 22:29:18 -0300 | [diff] [blame] | 181 | .desc = "Share thread maps", |
| 182 | .func = test__thread_maps_share, |
Jiri Olsa | fabf01238 | 2014-03-17 14:39:00 +0100 | [diff] [blame] | 183 | }, |
| 184 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 185 | .desc = "Sort output of hist entries", |
Namhyung Kim | f21d181 | 2014-05-12 14:43:18 +0900 | [diff] [blame] | 186 | .func = test__hists_output, |
| 187 | }, |
| 188 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 189 | .desc = "Cumulate child hist entries", |
Namhyung Kim | 0506aec | 2014-05-23 18:04:42 +0900 | [diff] [blame] | 190 | .func = test__hists_cumulate, |
| 191 | }, |
| 192 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 193 | .desc = "Track with sched_switch", |
Adrian Hunter | d44bc55 | 2014-08-15 22:08:36 +0300 | [diff] [blame] | 194 | .func = test__switch_tracking, |
| 195 | }, |
| 196 | { |
Arnaldo Carvalho de Melo | 1b85337 | 2014-09-03 18:02:59 -0300 | [diff] [blame] | 197 | .desc = "Filter fds with revents mask in a fdarray", |
| 198 | .func = test__fdarray__filter, |
Arnaldo Carvalho de Melo | 54dbfae | 2014-08-12 23:34:06 -0300 | [diff] [blame] | 199 | }, |
| 200 | { |
Arnaldo Carvalho de Melo | 1b85337 | 2014-09-03 18:02:59 -0300 | [diff] [blame] | 201 | .desc = "Add fd to a fdarray, making it autogrow", |
| 202 | .func = test__fdarray__add, |
Arnaldo Carvalho de Melo | 9ae2803 | 2014-08-18 16:49:00 -0300 | [diff] [blame] | 203 | }, |
| 204 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 205 | .desc = "kmod_path__parse", |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 206 | .func = test__kmod_path__parse, |
| 207 | }, |
| 208 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 209 | .desc = "Thread map", |
Jiri Olsa | 134aa44 | 2015-06-26 11:29:08 +0200 | [diff] [blame] | 210 | .func = test__thread_map, |
| 211 | }, |
| 212 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 213 | .desc = "LLVM search and compile", |
Wang Nan | 9bc898c | 2015-07-08 10:04:02 +0000 | [diff] [blame] | 214 | .func = test__llvm, |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 215 | .subtest = { |
| 216 | .skip_if_fail = true, |
| 217 | .get_nr = test__llvm_subtest_get_nr, |
| 218 | .get_desc = test__llvm_subtest_get_desc, |
| 219 | }, |
Wang Nan | 9bc898c | 2015-07-08 10:04:02 +0000 | [diff] [blame] | 220 | }, |
| 221 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 222 | .desc = "Session topology", |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 223 | .func = test__session_topology, |
Kan Liang | c84974e | 2015-09-04 04:58:31 -0400 | [diff] [blame] | 224 | }, |
| 225 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 226 | .desc = "BPF filter", |
Wang Nan | ba1fae4 | 2015-11-06 13:49:43 +0000 | [diff] [blame] | 227 | .func = test__bpf, |
Wang Nan | 77a0cf6 | 2015-11-17 08:32:49 +0000 | [diff] [blame] | 228 | .subtest = { |
| 229 | .skip_if_fail = true, |
| 230 | .get_nr = test__bpf_subtest_get_nr, |
| 231 | .get_desc = test__bpf_subtest_get_desc, |
| 232 | }, |
Wang Nan | ba1fae4 | 2015-11-06 13:49:43 +0000 | [diff] [blame] | 233 | }, |
| 234 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 235 | .desc = "Synthesize thread map", |
Jiri Olsa | 99471c9 | 2015-10-25 15:51:20 +0100 | [diff] [blame] | 236 | .func = test__thread_map_synthesize, |
| 237 | }, |
| 238 | { |
Jiri Olsa | 38af91f | 2016-12-12 11:35:41 +0100 | [diff] [blame] | 239 | .desc = "Remove thread map", |
| 240 | .func = test__thread_map_remove, |
| 241 | }, |
| 242 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 243 | .desc = "Synthesize cpu map", |
Jiri Olsa | 6c87290 | 2015-10-25 15:51:24 +0100 | [diff] [blame] | 244 | .func = test__cpu_map_synthesize, |
| 245 | }, |
| 246 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 247 | .desc = "Synthesize stat config", |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 248 | .func = test__synthesize_stat_config, |
| 249 | }, |
| 250 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 251 | .desc = "Synthesize stat", |
Jiri Olsa | 5796f8f | 2015-10-25 15:51:31 +0100 | [diff] [blame] | 252 | .func = test__synthesize_stat, |
| 253 | }, |
| 254 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 255 | .desc = "Synthesize stat round", |
Jiri Olsa | d4c2259 | 2015-10-25 15:51:34 +0100 | [diff] [blame] | 256 | .func = test__synthesize_stat_round, |
| 257 | }, |
| 258 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 259 | .desc = "Synthesize attr update", |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 260 | .func = test__event_update, |
| 261 | }, |
| 262 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 263 | .desc = "Event times", |
Jiri Olsa | b31d660 | 2016-03-24 13:52:20 +0100 | [diff] [blame] | 264 | .func = test__event_times, |
| 265 | }, |
| 266 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 267 | .desc = "Read backward ring buffer", |
Wang Nan | ee74701 | 2016-05-09 01:47:51 +0000 | [diff] [blame] | 268 | .func = test__backward_ring_buffer, |
| 269 | }, |
| 270 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 271 | .desc = "Print cpu map", |
Jiri Olsa | a24020e | 2016-06-28 13:29:04 +0200 | [diff] [blame] | 272 | .func = test__cpu_map_print, |
| 273 | }, |
| 274 | { |
Andi Kleen | a2408a7 | 2019-11-20 16:15:14 -0800 | [diff] [blame] | 275 | .desc = "Merge cpu map", |
| 276 | .func = test__cpu_map_merge, |
| 277 | }, |
| 278 | |
| 279 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 280 | .desc = "Probe SDT events", |
Masami Hiramatsu | 8e5dc84 | 2016-07-12 19:06:05 +0900 | [diff] [blame] | 281 | .func = test__sdt_event, |
| 282 | }, |
| 283 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 284 | .desc = "is_printable_array", |
Jiri Olsa | 988dd77 | 2016-07-16 18:11:20 +0200 | [diff] [blame] | 285 | .func = test__is_printable_array, |
| 286 | }, |
| 287 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 288 | .desc = "Print bitmap", |
Jiri Olsa | ff3e33b | 2016-08-01 20:02:32 +0200 | [diff] [blame] | 289 | .func = test__bitmap_print, |
| 290 | }, |
| 291 | { |
Arnaldo Carvalho de Melo | 030910c | 2016-11-29 12:38:14 -0300 | [diff] [blame] | 292 | .desc = "perf hooks", |
Wang Nan | a074865 | 2016-11-26 07:03:28 +0000 | [diff] [blame] | 293 | .func = test__perf_hooks, |
| 294 | }, |
| 295 | { |
Wang Nan | 00b8669 | 2016-11-26 07:03:34 +0000 | [diff] [blame] | 296 | .desc = "builtin clang support", |
| 297 | .func = test__clang, |
| 298 | .subtest = { |
| 299 | .skip_if_fail = true, |
| 300 | .get_nr = test__clang_subtest_get_nr, |
| 301 | .get_desc = test__clang_subtest_get_desc, |
| 302 | } |
| 303 | }, |
| 304 | { |
Jiri Olsa | 9808143 | 2017-01-09 10:51:55 +0100 | [diff] [blame] | 305 | .desc = "unit_number__scnprintf", |
| 306 | .func = test__unit_number__scnprint, |
| 307 | }, |
| 308 | { |
Jiri Olsa | 8185850 | 2018-03-09 11:14:36 +0100 | [diff] [blame] | 309 | .desc = "mem2node", |
| 310 | .func = test__mem2node, |
| 311 | }, |
| 312 | { |
Adrian Hunter | e39a12c | 2019-06-04 16:00:16 +0300 | [diff] [blame] | 313 | .desc = "time utils", |
| 314 | .func = test__time_utils, |
| 315 | }, |
| 316 | { |
Ian Rogers | fa7f7e7 | 2019-11-26 15:59:13 -0800 | [diff] [blame] | 317 | .desc = "Test jit_write_elf", |
| 318 | .func = test__jit_write_elf, |
| 319 | }, |
| 320 | { |
Stephane Eranian | 7094349 | 2020-05-05 11:29:43 -0700 | [diff] [blame] | 321 | .desc = "Test libpfm4 support", |
| 322 | .func = test__pfm, |
| 323 | .subtest = { |
| 324 | .skip_if_fail = true, |
| 325 | .get_nr = test__pfm_subtest_get_nr, |
| 326 | .get_desc = test__pfm_subtest_get_desc, |
| 327 | } |
| 328 | }, |
| 329 | { |
Ian Rogers | e95770a | 2020-04-14 22:40:49 -0700 | [diff] [blame] | 330 | .desc = "Test api io", |
| 331 | .func = test__api_io, |
| 332 | }, |
| 333 | { |
Arnaldo Carvalho de Melo | a573268 | 2019-11-25 22:33:02 -0300 | [diff] [blame] | 334 | .desc = "maps__merge_in", |
| 335 | .func = test__maps__merge_in, |
Jiri Olsa | 4f600bc | 2019-05-08 15:20:07 +0200 | [diff] [blame] | 336 | }, |
| 337 | { |
Nick Gasson | 525c821 | 2020-04-27 14:15:16 +0800 | [diff] [blame] | 338 | .desc = "Demangle Java", |
| 339 | .func = test__demangle_java, |
| 340 | }, |
| 341 | { |
Fabian Hemmer | cef7af2 | 2021-02-03 16:15:37 -0500 | [diff] [blame] | 342 | .desc = "Demangle OCaml", |
| 343 | .func = test__demangle_ocaml, |
| 344 | }, |
| 345 | { |
Jiri Olsa | 0a507af | 2020-06-02 23:47:40 +0200 | [diff] [blame] | 346 | .desc = "Parse and process metrics", |
| 347 | .func = test__parse_metric, |
| 348 | }, |
| 349 | { |
Remi Bernon | ed21d6d | 2020-08-21 18:52:38 +0200 | [diff] [blame] | 350 | .desc = "PE file support", |
| 351 | .func = test__pe_file_parsing, |
| 352 | }, |
| 353 | { |
Namhyung Kim | 40b74c30 | 2020-09-24 21:44:55 +0900 | [diff] [blame] | 354 | .desc = "Event expansion for cgroups", |
| 355 | .func = test__expand_cgroup_events, |
| 356 | }, |
| 357 | { |
Leo Yan | 3989bbf | 2020-10-19 18:02:35 +0800 | [diff] [blame] | 358 | .desc = "Convert perf time to TSC", |
| 359 | .func = test__perf_time_to_tsc, |
Leo Yan | 248dd9b | 2020-10-19 18:02:36 +0800 | [diff] [blame] | 360 | .is_supported = test__tsc_is_supported, |
Leo Yan | 3989bbf | 2020-10-19 18:02:35 +0800 | [diff] [blame] | 361 | }, |
| 362 | { |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 363 | .func = NULL, |
| 364 | }, |
| 365 | }; |
| 366 | |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 367 | static struct test *tests[] = { |
| 368 | generic_tests, |
| 369 | arch_tests, |
| 370 | }; |
| 371 | |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 372 | static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[]) |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 373 | { |
| 374 | int i; |
| 375 | |
| 376 | if (argc == 0) |
| 377 | return true; |
| 378 | |
| 379 | for (i = 0; i < argc; ++i) { |
| 380 | char *end; |
| 381 | long nr = strtoul(argv[i], &end, 10); |
| 382 | |
| 383 | if (*end == '\0') { |
| 384 | if (nr == curr + 1) |
| 385 | return true; |
| 386 | continue; |
| 387 | } |
| 388 | |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 389 | if (strcasestr(desc, argv[i])) |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 390 | return true; |
| 391 | } |
| 392 | |
| 393 | return false; |
| 394 | } |
| 395 | |
Arnaldo Carvalho de Melo | 721a1f5 | 2015-11-19 12:01:48 -0300 | [diff] [blame] | 396 | static int run_test(struct test *test, int subtest) |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 397 | { |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 398 | int status, err = -1, child = dont_fork ? 0 : fork(); |
Masami Hiramatsu | ba3dfff | 2014-08-14 02:22:45 +0000 | [diff] [blame] | 399 | char sbuf[STRERR_BUFSIZE]; |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 400 | |
| 401 | if (child < 0) { |
Masami Hiramatsu | ba3dfff | 2014-08-14 02:22:45 +0000 | [diff] [blame] | 402 | pr_err("failed to fork test: %s\n", |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 403 | str_error_r(errno, sbuf, sizeof(sbuf))); |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | if (!child) { |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 408 | if (!dont_fork) { |
| 409 | pr_debug("test child forked, pid %d\n", getpid()); |
Wang Nan | 5bcf2fe | 2015-11-17 08:32:50 +0000 | [diff] [blame] | 410 | |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 411 | if (verbose <= 0) { |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 412 | int nullfd = open("/dev/null", O_WRONLY); |
| 413 | |
| 414 | if (nullfd >= 0) { |
| 415 | close(STDERR_FILENO); |
| 416 | close(STDOUT_FILENO); |
| 417 | |
| 418 | dup2(nullfd, STDOUT_FILENO); |
| 419 | dup2(STDOUT_FILENO, STDERR_FILENO); |
| 420 | close(nullfd); |
| 421 | } |
| 422 | } else { |
| 423 | signal(SIGSEGV, sighandler_dump_stack); |
| 424 | signal(SIGFPE, sighandler_dump_stack); |
Wang Nan | 5bcf2fe | 2015-11-17 08:32:50 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 428 | err = test->func(test, subtest); |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 429 | if (!dont_fork) |
| 430 | exit(err); |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 431 | } |
| 432 | |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 433 | if (!dont_fork) { |
| 434 | wait(&status); |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 435 | |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 436 | if (WIFEXITED(status)) { |
| 437 | err = (signed char)WEXITSTATUS(status); |
| 438 | pr_debug("test child finished with %d\n", err); |
| 439 | } else if (WIFSIGNALED(status)) { |
| 440 | err = -1; |
| 441 | pr_debug("test child interrupted\n"); |
| 442 | } |
Jiri Olsa | 0d8a5fa | 2014-05-10 17:22:30 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | return err; |
| 446 | } |
| 447 | |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 448 | #define for_each_test(j, t) \ |
| 449 | for (j = 0; j < ARRAY_SIZE(tests); j++) \ |
| 450 | for (t = &tests[j][0]; t->func; t++) |
Matt Fleming | e8210ce | 2015-09-05 20:02:20 +0100 | [diff] [blame] | 451 | |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 452 | static int test_and_print(struct test *t, bool force_skip, int subtest) |
| 453 | { |
| 454 | int err; |
| 455 | |
| 456 | if (!force_skip) { |
| 457 | pr_debug("\n--- start ---\n"); |
| 458 | err = run_test(t, subtest); |
| 459 | pr_debug("---- end ----\n"); |
| 460 | } else { |
| 461 | pr_debug("\n--- force skipped ---\n"); |
| 462 | err = TEST_SKIP; |
| 463 | } |
| 464 | |
| 465 | if (!t->subtest.get_nr) |
| 466 | pr_debug("%s:", t->desc); |
| 467 | else |
Sandipan Das | aa90f9f | 2018-07-26 22:47:33 +0530 | [diff] [blame] | 468 | pr_debug("%s subtest %d:", t->desc, subtest + 1); |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 469 | |
| 470 | switch (err) { |
| 471 | case TEST_OK: |
| 472 | pr_info(" Ok\n"); |
| 473 | break; |
Ian Rogers | 3b53665 | 2020-05-13 14:29:33 -0700 | [diff] [blame] | 474 | case TEST_SKIP: { |
| 475 | const char *skip_reason = NULL; |
| 476 | if (t->subtest.skip_reason) |
| 477 | skip_reason = t->subtest.skip_reason(subtest); |
| 478 | if (skip_reason) |
| 479 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (%s)\n", skip_reason); |
| 480 | else |
| 481 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); |
| 482 | } |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 483 | break; |
| 484 | case TEST_FAIL: |
| 485 | default: |
| 486 | color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); |
| 487 | break; |
| 488 | } |
| 489 | |
| 490 | return err; |
| 491 | } |
| 492 | |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 493 | static const char *shell_test__description(char *description, size_t size, |
| 494 | const char *path, const char *name) |
| 495 | { |
| 496 | FILE *fp; |
| 497 | char filename[PATH_MAX]; |
| 498 | |
| 499 | path__join(filename, sizeof(filename), path, name); |
| 500 | fp = fopen(filename, "r"); |
| 501 | if (!fp) |
| 502 | return NULL; |
| 503 | |
Michael Petlan | 4eaf97e | 2018-11-21 16:39:18 -0500 | [diff] [blame] | 504 | /* Skip shebang */ |
| 505 | while (fgetc(fp) != '\n'); |
| 506 | |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 507 | description = fgets(description, size, fp); |
| 508 | fclose(fp); |
| 509 | |
Arnaldo Carvalho de Melo | 3ca43b6 | 2019-06-26 12:06:20 -0300 | [diff] [blame] | 510 | return description ? strim(description + 1) : NULL; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 511 | } |
| 512 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 513 | #define for_each_shell_test(entlist, nr, base, ent) \ |
| 514 | for (int __i = 0; __i < nr && (ent = entlist[__i]); __i++) \ |
Kim Phillips | db8fec5 | 2018-06-29 12:46:58 -0500 | [diff] [blame] | 515 | if (!is_directory(base, ent) && ent->d_name[0] != '.') |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 516 | |
| 517 | static const char *shell_tests__dir(char *path, size_t size) |
| 518 | { |
| 519 | const char *devel_dirs[] = { "./tools/perf/tests", "./tests", }; |
| 520 | char *exec_path; |
| 521 | unsigned int i; |
| 522 | |
| 523 | for (i = 0; i < ARRAY_SIZE(devel_dirs); ++i) { |
| 524 | struct stat st; |
| 525 | if (!lstat(devel_dirs[i], &st)) { |
| 526 | scnprintf(path, size, "%s/shell", devel_dirs[i]); |
| 527 | if (!lstat(devel_dirs[i], &st)) |
| 528 | return path; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | /* Then installed path. */ |
| 533 | exec_path = get_argv_exec_path(); |
| 534 | scnprintf(path, size, "%s/tests/shell", exec_path); |
| 535 | free(exec_path); |
| 536 | return path; |
| 537 | } |
| 538 | |
| 539 | static int shell_tests__max_desc_width(void) |
| 540 | { |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 541 | struct dirent **entlist; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 542 | struct dirent *ent; |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 543 | int n_dirs; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 544 | char path_dir[PATH_MAX]; |
| 545 | const char *path = shell_tests__dir(path_dir, sizeof(path_dir)); |
| 546 | int width = 0; |
| 547 | |
| 548 | if (path == NULL) |
| 549 | return -1; |
| 550 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 551 | n_dirs = scandir(path, &entlist, NULL, alphasort); |
| 552 | if (n_dirs == -1) |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 553 | return -1; |
| 554 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 555 | for_each_shell_test(entlist, n_dirs, path, ent) { |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 556 | char bf[256]; |
| 557 | const char *desc = shell_test__description(bf, sizeof(bf), path, ent->d_name); |
| 558 | |
| 559 | if (desc) { |
| 560 | int len = strlen(desc); |
| 561 | |
| 562 | if (width < len) |
| 563 | width = len; |
| 564 | } |
| 565 | } |
| 566 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 567 | free(entlist); |
| 568 | |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 569 | return width; |
| 570 | } |
| 571 | |
| 572 | struct shell_test { |
| 573 | const char *dir; |
| 574 | const char *file; |
| 575 | }; |
| 576 | |
| 577 | static int shell_test__run(struct test *test, int subdir __maybe_unused) |
| 578 | { |
| 579 | int err; |
| 580 | char script[PATH_MAX]; |
| 581 | struct shell_test *st = test->priv; |
| 582 | |
Ian Rogers | e3c9cfd | 2021-06-21 14:56:46 -0700 | [diff] [blame^] | 583 | path__join(script, sizeof(script) - 3, st->dir, st->file); |
| 584 | |
| 585 | if (verbose) |
| 586 | strncat(script, " -v", sizeof(script) - strlen(script) - 1); |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 587 | |
| 588 | err = system(script); |
| 589 | if (!err) |
| 590 | return TEST_OK; |
| 591 | |
| 592 | return WEXITSTATUS(err) == 2 ? TEST_SKIP : TEST_FAIL; |
| 593 | } |
| 594 | |
| 595 | static int run_shell_tests(int argc, const char *argv[], int i, int width) |
| 596 | { |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 597 | struct dirent **entlist; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 598 | struct dirent *ent; |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 599 | int n_dirs; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 600 | char path_dir[PATH_MAX]; |
| 601 | struct shell_test st = { |
| 602 | .dir = shell_tests__dir(path_dir, sizeof(path_dir)), |
| 603 | }; |
| 604 | |
| 605 | if (st.dir == NULL) |
| 606 | return -1; |
| 607 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 608 | n_dirs = scandir(st.dir, &entlist, NULL, alphasort); |
| 609 | if (n_dirs == -1) { |
Ian Rogers | b2bf666 | 2020-03-12 17:56:02 -0700 | [diff] [blame] | 610 | pr_err("failed to open shell test directory: %s\n", |
| 611 | st.dir); |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 612 | return -1; |
Ian Rogers | b2bf666 | 2020-03-12 17:56:02 -0700 | [diff] [blame] | 613 | } |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 614 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 615 | for_each_shell_test(entlist, n_dirs, st.dir, ent) { |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 616 | int curr = i++; |
| 617 | char desc[256]; |
| 618 | struct test test = { |
| 619 | .desc = shell_test__description(desc, sizeof(desc), st.dir, ent->d_name), |
| 620 | .func = shell_test__run, |
| 621 | .priv = &st, |
| 622 | }; |
| 623 | |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 624 | if (!perf_test__matches(test.desc, curr, argc, argv)) |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 625 | continue; |
| 626 | |
| 627 | st.file = ent->d_name; |
| 628 | pr_info("%2d: %-*s:", i, width, test.desc); |
| 629 | test_and_print(&test, false, -1); |
| 630 | } |
| 631 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 632 | free(entlist); |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 636 | 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] | 637 | { |
Matt Fleming | e8210ce | 2015-09-05 20:02:20 +0100 | [diff] [blame] | 638 | struct test *t; |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 639 | unsigned int j; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 640 | int i = 0; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 641 | int width = shell_tests__max_desc_width(); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 642 | |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 643 | for_each_test(j, t) { |
Matt Fleming | e8210ce | 2015-09-05 20:02:20 +0100 | [diff] [blame] | 644 | int len = strlen(t->desc); |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 645 | |
| 646 | if (width < len) |
| 647 | width = len; |
Arnaldo Carvalho de Melo | 9a8e85a | 2012-10-24 15:44:41 -0200 | [diff] [blame] | 648 | } |
Jiri Olsa | 945aea2 | 2012-10-30 23:01:43 +0100 | [diff] [blame] | 649 | |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 650 | for_each_test(j, t) { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 651 | int curr = i++, err; |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 652 | int subi; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 653 | |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 654 | if (!perf_test__matches(t->desc, curr, argc, argv)) { |
| 655 | bool skip = true; |
| 656 | int subn; |
| 657 | |
| 658 | if (!t->subtest.get_nr) |
| 659 | continue; |
| 660 | |
| 661 | subn = t->subtest.get_nr(); |
| 662 | |
| 663 | for (subi = 0; subi < subn; subi++) { |
| 664 | if (perf_test__matches(t->subtest.get_desc(subi), curr, argc, argv)) |
| 665 | skip = false; |
| 666 | } |
| 667 | |
| 668 | if (skip) |
| 669 | continue; |
| 670 | } |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 671 | |
Jiri Olsa | 598762c | 2017-06-01 22:54:50 +0200 | [diff] [blame] | 672 | if (t->is_supported && !t->is_supported()) { |
| 673 | pr_debug("%2d: %-*s: Disabled\n", i, width, t->desc); |
| 674 | continue; |
| 675 | } |
| 676 | |
Matt Fleming | e8210ce | 2015-09-05 20:02:20 +0100 | [diff] [blame] | 677 | pr_info("%2d: %-*s:", i, width, t->desc); |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 678 | |
| 679 | if (intlist__find(skiplist, i)) { |
| 680 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); |
| 681 | continue; |
| 682 | } |
| 683 | |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 684 | if (!t->subtest.get_nr) { |
| 685 | test_and_print(t, false, -1); |
| 686 | } else { |
| 687 | int subn = t->subtest.get_nr(); |
| 688 | /* |
| 689 | * minus 2 to align with normal testcases. |
| 690 | * For subtest we print additional '.x' in number. |
| 691 | * for example: |
| 692 | * |
| 693 | * 35: Test LLVM searching and compiling : |
| 694 | * 35.1: Basic BPF llvm compiling test : Ok |
| 695 | */ |
| 696 | int subw = width > 2 ? width - 2 : width; |
| 697 | bool skip = false; |
Jiri Olsa | f4c1ea5 | 2012-12-19 11:33:39 -0300 | [diff] [blame] | 698 | |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 699 | if (subn <= 0) { |
| 700 | color_fprintf(stderr, PERF_COLOR_YELLOW, |
| 701 | " Skip (not compiled in)\n"); |
| 702 | continue; |
| 703 | } |
| 704 | pr_info("\n"); |
| 705 | |
| 706 | for (subi = 0; subi < subn; subi++) { |
| 707 | int len = strlen(t->subtest.get_desc(subi)); |
| 708 | |
| 709 | if (subw < len) |
| 710 | subw = len; |
| 711 | } |
| 712 | |
| 713 | for (subi = 0; subi < subn; subi++) { |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 714 | if (!perf_test__matches(t->subtest.get_desc(subi), curr, argc, argv)) |
| 715 | continue; |
| 716 | |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 717 | pr_info("%2d.%1d: %-*s:", i, subi + 1, subw, |
| 718 | t->subtest.get_desc(subi)); |
Sandipan Das | aa90f9f | 2018-07-26 22:47:33 +0530 | [diff] [blame] | 719 | err = test_and_print(t, skip, subi); |
Wang Nan | e8c6d50 | 2015-11-17 08:32:48 +0000 | [diff] [blame] | 720 | if (err != TEST_OK && t->subtest.skip_if_fail) |
| 721 | skip = true; |
| 722 | } |
Jiri Olsa | f4c1ea5 | 2012-12-19 11:33:39 -0300 | [diff] [blame] | 723 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 724 | } |
| 725 | |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 726 | return run_shell_tests(argc, argv, i, width); |
| 727 | } |
| 728 | |
| 729 | static int perf_test__list_shell(int argc, const char **argv, int i) |
| 730 | { |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 731 | struct dirent **entlist; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 732 | struct dirent *ent; |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 733 | int n_dirs; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 734 | char path_dir[PATH_MAX]; |
| 735 | const char *path = shell_tests__dir(path_dir, sizeof(path_dir)); |
| 736 | |
| 737 | if (path == NULL) |
| 738 | return -1; |
| 739 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 740 | n_dirs = scandir(path, &entlist, NULL, alphasort); |
| 741 | if (n_dirs == -1) |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 742 | return -1; |
| 743 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 744 | for_each_shell_test(entlist, n_dirs, path, ent) { |
Arnaldo Carvalho de Melo | 6d02acc | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 745 | int curr = i++; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 746 | char bf[256]; |
Arnaldo Carvalho de Melo | 6d02acc | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 747 | struct test t = { |
| 748 | .desc = shell_test__description(bf, sizeof(bf), path, ent->d_name), |
| 749 | }; |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 750 | |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 751 | if (!perf_test__matches(t.desc, curr, argc, argv)) |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 752 | continue; |
| 753 | |
Arnaldo Carvalho de Melo | 6d02acc | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 754 | pr_info("%2d: %s\n", i, t.desc); |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 755 | } |
| 756 | |
Riccardo Mancini | da96383 | 2021-05-26 01:05:17 +0200 | [diff] [blame] | 757 | free(entlist); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 761 | static int perf_test__list(int argc, const char **argv) |
| 762 | { |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 763 | unsigned int j; |
Matt Fleming | e8210ce | 2015-09-05 20:02:20 +0100 | [diff] [blame] | 764 | struct test *t; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 765 | int i = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 766 | |
Matt Fleming | 31b6753 | 2015-10-05 15:40:19 +0100 | [diff] [blame] | 767 | for_each_test(j, t) { |
Arnaldo Carvalho de Melo | 6d02acc | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 768 | int curr = i++; |
Arnaldo Carvalho de Melo | 28765bf | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 769 | |
Jiri Olsa | d685e6c | 2020-05-25 00:42:06 +0200 | [diff] [blame] | 770 | if (!perf_test__matches(t->desc, curr, argc, argv) || |
Arnaldo Carvalho de Melo | 6d02acc | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 771 | (t->is_supported && !t->is_supported())) |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 772 | continue; |
| 773 | |
Arnaldo Carvalho de Melo | 28765bf | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 774 | pr_info("%2d: %s\n", i, t->desc); |
Hendrik Brueckner | ea40b6d | 2018-04-13 09:42:23 +0200 | [diff] [blame] | 775 | |
| 776 | if (t->subtest.get_nr) { |
| 777 | int subn = t->subtest.get_nr(); |
| 778 | int subi; |
| 779 | |
| 780 | for (subi = 0; subi < subn; subi++) |
| 781 | pr_info("%2d:%1d: %s\n", i, subi + 1, |
| 782 | t->subtest.get_desc(subi)); |
| 783 | } |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 784 | } |
| 785 | |
Arnaldo Carvalho de Melo | 1209b27 | 2017-08-03 16:49:15 -0300 | [diff] [blame] | 786 | perf_test__list_shell(argc, argv, i); |
| 787 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 788 | return 0; |
| 789 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 790 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 791 | int cmd_test(int argc, const char **argv) |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 792 | { |
Yunlong Song | 1f9975f | 2015-03-18 21:35:55 +0800 | [diff] [blame] | 793 | const char *test_usage[] = { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 794 | "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", |
| 795 | NULL, |
| 796 | }; |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 797 | const char *skip = NULL; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 798 | const struct option test_options[] = { |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 799 | OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), |
Namhyung Kim | c30ab8a | 2012-01-08 02:25:26 +0900 | [diff] [blame] | 800 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 801 | "be more verbose (show symbol address, etc)"), |
Jiri Olsa | 7fa9b8f | 2016-06-28 13:29:01 +0200 | [diff] [blame] | 802 | OPT_BOOLEAN('F', "dont-fork", &dont_fork, |
| 803 | "Do not fork for testcase"), |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 804 | OPT_END() |
| 805 | }; |
Yunlong Song | 1f9975f | 2015-03-18 21:35:55 +0800 | [diff] [blame] | 806 | const char * const test_subcommands[] = { "list", NULL }; |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 807 | struct intlist *skiplist = NULL; |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 808 | int ret = hists__init(); |
| 809 | |
| 810 | if (ret < 0) |
| 811 | return ret; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 812 | |
Yunlong Song | 1f9975f | 2015-03-18 21:35:55 +0800 | [diff] [blame] | 813 | argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 814 | if (argc >= 1 && !strcmp(argv[0], "list")) |
Arnaldo Carvalho de Melo | 6d02acc | 2017-08-04 11:16:40 -0300 | [diff] [blame] | 815 | return perf_test__list(argc - 1, argv + 1); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 816 | |
| 817 | symbol_conf.priv_size = sizeof(int); |
| 818 | symbol_conf.sort_by_name = true; |
| 819 | symbol_conf.try_vmlinux_path = true; |
| 820 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 821 | if (symbol__init(NULL) < 0) |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 822 | return -1; |
| 823 | |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 824 | if (skip != NULL) |
| 825 | skiplist = intlist__new(skip); |
Arnaldo Carvalho de Melo | d3280ce | 2019-07-09 16:27:01 -0300 | [diff] [blame] | 826 | /* |
| 827 | * Tests that create BPF maps, for instance, need more than the 64K |
| 828 | * default: |
| 829 | */ |
| 830 | rlimit__bump_memlock(); |
Arnaldo Carvalho de Melo | 2ae8287 | 2013-01-24 16:22:55 -0300 | [diff] [blame] | 831 | |
| 832 | return __cmd_test(argc, argv, skiplist); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 833 | } |