builtin-test.c (54df5c8e014c52726a71a6c11534b9cd2df31039) builtin-test.c (df2252054eb0f9f65389f3911588256bcc4f973b)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * builtin-test.c
4 *
5 * Builtin regression testing command: ever growing number of sanity tests
6 */
7#include <fcntl.h>
8#include <errno.h>

--- 16 unchanged lines hidden (view full) ---

25#include "util/rlimit.h"
26#include <linux/kernel.h>
27#include <linux/string.h>
28#include <subcmd/exec-cmd.h>
29#include <linux/zalloc.h>
30
31static bool dont_fork;
32
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * builtin-test.c
4 *
5 * Builtin regression testing command: ever growing number of sanity tests
6 */
7#include <fcntl.h>
8#include <errno.h>

--- 16 unchanged lines hidden (view full) ---

25#include "util/rlimit.h"
26#include <linux/kernel.h>
27#include <linux/string.h>
28#include <subcmd/exec-cmd.h>
29#include <linux/zalloc.h>
30
31static bool dont_fork;
32
33struct test __weak arch_tests[] = {
34 {
35 .func = NULL,
36 },
33struct test *__weak arch_tests[] = {
34 NULL,
37};
38
35};
36
39#define DEFINE_SUITE(description, name) \
40 { \
41 .desc = description, \
42 .func = test__##name, \
43 }
44
45static struct test generic_tests[] = {
46DEFINE_SUITE("vmlinux symtab matches kallsyms", vmlinux_matches_kallsyms),
47DEFINE_SUITE("Detect openat syscall event", openat_syscall_event),
48DEFINE_SUITE("Detect openat syscall event on all cpus", openat_syscall_event_on_all_cpus),
49DEFINE_SUITE("Read samples using the mmap interface", basic_mmap),
50DEFINE_SUITE("Test data source output", mem),
51DEFINE_SUITE("Parse event definition strings", parse_events),
52DEFINE_SUITE("Simple expression parser", expr),
53DEFINE_SUITE("PERF_RECORD_* events & perf_sample fields", PERF_RECORD),
54DEFINE_SUITE("Parse perf pmu format", pmu),
55{
37DEFINE_SUITE("vmlinux symtab matches kallsyms", vmlinux_matches_kallsyms);
38DEFINE_SUITE("Detect openat syscall event", openat_syscall_event);
39DEFINE_SUITE("Detect openat syscall event on all cpus", openat_syscall_event_on_all_cpus);
40DEFINE_SUITE("Read samples using the mmap interface", basic_mmap);
41DEFINE_SUITE("Test data source output", mem);
42DEFINE_SUITE("Parse event definition strings", parse_events);
43DEFINE_SUITE("Simple expression parser", expr);
44DEFINE_SUITE("PERF_RECORD_* events & perf_sample fields", PERF_RECORD);
45DEFINE_SUITE("Parse perf pmu format", pmu);
46static struct test pmu_events = {
56 .desc = "PMU events",
57 .func = test__pmu_events,
58 .subtest = {
59 .skip_if_fail = false,
60 .get_nr = test__pmu_events_subtest_get_nr,
61 .get_desc = test__pmu_events_subtest_get_desc,
62 .skip_reason = test__pmu_events_subtest_skip_reason,
63 },
47 .desc = "PMU events",
48 .func = test__pmu_events,
49 .subtest = {
50 .skip_if_fail = false,
51 .get_nr = test__pmu_events_subtest_get_nr,
52 .get_desc = test__pmu_events_subtest_get_desc,
53 .skip_reason = test__pmu_events_subtest_skip_reason,
54 },
64
65},
66DEFINE_SUITE("DSO data read", dso_data),
67DEFINE_SUITE("DSO data cache", dso_data_cache),
68DEFINE_SUITE("DSO data reopen", dso_data_reopen),
69DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test),
70DEFINE_SUITE("Parse sched tracepoints fields", perf_evsel__tp_sched_test),
71DEFINE_SUITE("syscalls:sys_enter_openat event fields", syscall_openat_tp_fields),
72DEFINE_SUITE("Setup struct perf_event_attr", attr),
73DEFINE_SUITE("Match and link multiple hists", hists_link),
74DEFINE_SUITE("'import perf' in python", python_use),
75{
55};
56DEFINE_SUITE("DSO data read", dso_data);
57DEFINE_SUITE("DSO data cache", dso_data_cache);
58DEFINE_SUITE("DSO data reopen", dso_data_reopen);
59DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test);
60DEFINE_SUITE("Parse sched tracepoints fields", perf_evsel__tp_sched_test);
61DEFINE_SUITE("syscalls:sys_enter_openat event fields", syscall_openat_tp_fields);
62DEFINE_SUITE("Setup struct perf_event_attr", attr);
63DEFINE_SUITE("Match and link multiple hists", hists_link);
64DEFINE_SUITE("'import perf' in python", python_use);
65static struct test bp_signal = {
76 .desc = "Breakpoint overflow signal handler",
77 .func = test__bp_signal,
78 .is_supported = test__bp_signal_is_supported,
66 .desc = "Breakpoint overflow signal handler",
67 .func = test__bp_signal,
68 .is_supported = test__bp_signal_is_supported,
79},
80{
69};
70static struct test bp_signal_overflow = {
81 .desc = "Breakpoint overflow sampling",
82 .func = test__bp_signal_overflow,
83 .is_supported = test__bp_signal_is_supported,
71 .desc = "Breakpoint overflow sampling",
72 .func = test__bp_signal_overflow,
73 .is_supported = test__bp_signal_is_supported,
84},
85{
74};
75static struct test bp_accounting = {
86 .desc = "Breakpoint accounting",
87 .func = test__bp_accounting,
88 .is_supported = test__bp_account_is_supported,
76 .desc = "Breakpoint accounting",
77 .func = test__bp_accounting,
78 .is_supported = test__bp_account_is_supported,
89},
90{
79};
80static struct test wp = {
91 .desc = "Watchpoint",
92 .func = test__wp,
93 .is_supported = test__wp_is_supported,
94 .subtest = {
95 .skip_if_fail = false,
96 .get_nr = test__wp_subtest_get_nr,
97 .get_desc = test__wp_subtest_get_desc,
98 .skip_reason = test__wp_subtest_skip_reason,
99 },
81 .desc = "Watchpoint",
82 .func = test__wp,
83 .is_supported = test__wp_is_supported,
84 .subtest = {
85 .skip_if_fail = false,
86 .get_nr = test__wp_subtest_get_nr,
87 .get_desc = test__wp_subtest_get_desc,
88 .skip_reason = test__wp_subtest_skip_reason,
89 },
100},
101DEFINE_SUITE("Number of exit events of a simple workload", task_exit),
102DEFINE_SUITE("Software clock events period values", sw_clock_freq),
103DEFINE_SUITE("Object code reading", code_reading),
104DEFINE_SUITE("Sample parsing", sample_parsing),
105DEFINE_SUITE("Use a dummy software event to keep tracking", keep_tracking),
106DEFINE_SUITE("Parse with no sample_id_all bit set", parse_no_sample_id_all),
107DEFINE_SUITE("Filter hist entries", hists_filter),
108DEFINE_SUITE("Lookup mmap thread", mmap_thread_lookup),
109DEFINE_SUITE("Share thread maps", thread_maps_share),
110DEFINE_SUITE("Sort output of hist entries", hists_output),
111DEFINE_SUITE("Cumulate child hist entries", hists_cumulate),
112DEFINE_SUITE("Track with sched_switch", switch_tracking),
113DEFINE_SUITE("Filter fds with revents mask in a fdarray", fdarray__filter),
114DEFINE_SUITE("Add fd to a fdarray, making it autogrow", fdarray__add),
115DEFINE_SUITE("kmod_path__parse", kmod_path__parse),
116DEFINE_SUITE("Thread map", thread_map),
117{
90};
91DEFINE_SUITE("Number of exit events of a simple workload", task_exit);
92DEFINE_SUITE("Software clock events period values", sw_clock_freq);
93DEFINE_SUITE("Object code reading", code_reading);
94DEFINE_SUITE("Sample parsing", sample_parsing);
95DEFINE_SUITE("Use a dummy software event to keep tracking", keep_tracking);
96DEFINE_SUITE("Parse with no sample_id_all bit set", parse_no_sample_id_all);
97DEFINE_SUITE("Filter hist entries", hists_filter);
98DEFINE_SUITE("Lookup mmap thread", mmap_thread_lookup);
99DEFINE_SUITE("Share thread maps", thread_maps_share);
100DEFINE_SUITE("Sort output of hist entries", hists_output);
101DEFINE_SUITE("Cumulate child hist entries", hists_cumulate);
102DEFINE_SUITE("Track with sched_switch", switch_tracking);
103DEFINE_SUITE("Filter fds with revents mask in a fdarray", fdarray__filter);
104DEFINE_SUITE("Add fd to a fdarray, making it autogrow", fdarray__add);
105DEFINE_SUITE("kmod_path__parse", kmod_path__parse);
106DEFINE_SUITE("Thread map", thread_map);
107static struct test llvm = {
118 .desc = "LLVM search and compile",
119 .func = test__llvm,
120 .subtest = {
121 .skip_if_fail = true,
122 .get_nr = test__llvm_subtest_get_nr,
123 .get_desc = test__llvm_subtest_get_desc,
124 },
108 .desc = "LLVM search and compile",
109 .func = test__llvm,
110 .subtest = {
111 .skip_if_fail = true,
112 .get_nr = test__llvm_subtest_get_nr,
113 .get_desc = test__llvm_subtest_get_desc,
114 },
125},
126DEFINE_SUITE("Session topology", session_topology),
127{
115};
116DEFINE_SUITE("Session topology", session_topology);
117static struct test bpf = {
128 .desc = "BPF filter",
129 .func = test__bpf,
130 .subtest = {
131 .skip_if_fail = true,
132 .get_nr = test__bpf_subtest_get_nr,
133 .get_desc = test__bpf_subtest_get_desc,
134 },
118 .desc = "BPF filter",
119 .func = test__bpf,
120 .subtest = {
121 .skip_if_fail = true,
122 .get_nr = test__bpf_subtest_get_nr,
123 .get_desc = test__bpf_subtest_get_desc,
124 },
135},
136DEFINE_SUITE("Synthesize thread map", thread_map_synthesize),
137DEFINE_SUITE("Remove thread map", thread_map_remove),
138DEFINE_SUITE("Synthesize cpu map", cpu_map_synthesize),
139DEFINE_SUITE("Synthesize stat config", synthesize_stat_config),
140DEFINE_SUITE("Synthesize stat", synthesize_stat),
141DEFINE_SUITE("Synthesize stat round", synthesize_stat_round),
142DEFINE_SUITE("Synthesize attr update", event_update),
143DEFINE_SUITE("Event times", event_times),
144DEFINE_SUITE("Read backward ring buffer", backward_ring_buffer),
145DEFINE_SUITE("Print cpu map", cpu_map_print),
146DEFINE_SUITE("Merge cpu map", cpu_map_merge),
147DEFINE_SUITE("Probe SDT events", sdt_event),
148DEFINE_SUITE("is_printable_array", is_printable_array),
149DEFINE_SUITE("Print bitmap", bitmap_print),
150DEFINE_SUITE("perf hooks", perf_hooks),
151{
125};
126DEFINE_SUITE("Synthesize thread map", thread_map_synthesize);
127DEFINE_SUITE("Remove thread map", thread_map_remove);
128DEFINE_SUITE("Synthesize cpu map", cpu_map_synthesize);
129DEFINE_SUITE("Synthesize stat config", synthesize_stat_config);
130DEFINE_SUITE("Synthesize stat", synthesize_stat);
131DEFINE_SUITE("Synthesize stat round", synthesize_stat_round);
132DEFINE_SUITE("Synthesize attr update", event_update);
133DEFINE_SUITE("Event times", event_times);
134DEFINE_SUITE("Read backward ring buffer", backward_ring_buffer);
135DEFINE_SUITE("Print cpu map", cpu_map_print);
136DEFINE_SUITE("Merge cpu map", cpu_map_merge);
137DEFINE_SUITE("Probe SDT events", sdt_event);
138DEFINE_SUITE("is_printable_array", is_printable_array);
139DEFINE_SUITE("Print bitmap", bitmap_print);
140DEFINE_SUITE("perf hooks", perf_hooks);
141static struct test clang = {
152 .desc = "builtin clang support",
153 .func = test__clang,
154 .subtest = {
155 .skip_if_fail = true,
156 .get_nr = test__clang_subtest_get_nr,
157 .get_desc = test__clang_subtest_get_desc,
158 }
142 .desc = "builtin clang support",
143 .func = test__clang,
144 .subtest = {
145 .skip_if_fail = true,
146 .get_nr = test__clang_subtest_get_nr,
147 .get_desc = test__clang_subtest_get_desc,
148 }
159},
160DEFINE_SUITE("unit_number__scnprintf", unit_number__scnprint),
161DEFINE_SUITE("mem2node", mem2node),
162DEFINE_SUITE("time utils", time_utils),
163DEFINE_SUITE("Test jit_write_elf", jit_write_elf),
164{
149};
150DEFINE_SUITE("unit_number__scnprintf", unit_number__scnprint);
151DEFINE_SUITE("mem2node", mem2node);
152DEFINE_SUITE("time utils", time_utils);
153DEFINE_SUITE("Test jit_write_elf", jit_write_elf);
154static struct test pfm = {
165 .desc = "Test libpfm4 support",
166 .func = test__pfm,
167 .subtest = {
168 .skip_if_fail = true,
169 .get_nr = test__pfm_subtest_get_nr,
170 .get_desc = test__pfm_subtest_get_desc,
171 }
155 .desc = "Test libpfm4 support",
156 .func = test__pfm,
157 .subtest = {
158 .skip_if_fail = true,
159 .get_nr = test__pfm_subtest_get_nr,
160 .get_desc = test__pfm_subtest_get_desc,
161 }
172},
173DEFINE_SUITE("Test api io", api_io),
174DEFINE_SUITE("maps__merge_in", maps__merge_in),
175DEFINE_SUITE("Demangle Java", demangle_java),
176DEFINE_SUITE("Demangle OCaml", demangle_ocaml),
177DEFINE_SUITE("Parse and process metrics", parse_metric),
178DEFINE_SUITE("PE file support", pe_file_parsing),
179DEFINE_SUITE("Event expansion for cgroups", expand_cgroup_events),
180{
162};
163DEFINE_SUITE("Test api io", api_io);
164DEFINE_SUITE("maps__merge_in", maps__merge_in);
165DEFINE_SUITE("Demangle Java", demangle_java);
166DEFINE_SUITE("Demangle OCaml", demangle_ocaml);
167DEFINE_SUITE("Parse and process metrics", parse_metric);
168DEFINE_SUITE("PE file support", pe_file_parsing);
169DEFINE_SUITE("Event expansion for cgroups", expand_cgroup_events);
170static struct test perf_time_to_tsc = {
181 .desc = "Convert perf time to TSC",
182 .func = test__perf_time_to_tsc,
183 .is_supported = test__tsc_is_supported,
171 .desc = "Convert perf time to TSC",
172 .func = test__perf_time_to_tsc,
173 .is_supported = test__tsc_is_supported,
184},
185DEFINE_SUITE("dlfilter C API", dlfilter),
186{
187 .func = NULL,
188},
189};
174};
175DEFINE_SUITE("dlfilter C API", dlfilter);
190
176
191static struct test *tests[] = {
177
178static struct test *generic_tests[] = {
179 &vmlinux_matches_kallsyms,
180 &openat_syscall_event,
181 &openat_syscall_event_on_all_cpus,
182 &basic_mmap,
183 &mem,
184 &parse_events,
185 &expr,
186 &PERF_RECORD,
187 &pmu,
188 &pmu_events,
189 &dso_data,
190 &dso_data_cache,
191 &dso_data_reopen,
192 &perf_evsel__roundtrip_name_test,
193 &perf_evsel__tp_sched_test,
194 &syscall_openat_tp_fields,
195 &attr,
196 &hists_link,
197 &python_use,
198 &bp_signal,
199 &bp_signal_overflow,
200 &bp_accounting,
201 &wp,
202 &task_exit,
203 &sw_clock_freq,
204 &code_reading,
205 &sample_parsing,
206 &keep_tracking,
207 &parse_no_sample_id_all,
208 &hists_filter,
209 &mmap_thread_lookup,
210 &thread_maps_share,
211 &hists_output,
212 &hists_cumulate,
213 &switch_tracking,
214 &fdarray__filter,
215 &fdarray__add,
216 &kmod_path__parse,
217 &thread_map,
218 &llvm,
219 &session_topology,
220 &bpf,
221 &thread_map_synthesize,
222 &thread_map_remove,
223 &cpu_map_synthesize,
224 &synthesize_stat_config,
225 &synthesize_stat,
226 &synthesize_stat_round,
227 &event_update,
228 &event_times,
229 &backward_ring_buffer,
230 &cpu_map_print,
231 &cpu_map_merge,
232 &sdt_event,
233 &is_printable_array,
234 &bitmap_print,
235 &perf_hooks,
236 &clang,
237 &unit_number__scnprint,
238 &mem2node,
239 &time_utils,
240 &jit_write_elf,
241 &pfm,
242 &api_io,
243 &maps__merge_in,
244 &demangle_java,
245 &demangle_ocaml,
246 &parse_metric,
247 &pe_file_parsing,
248 &expand_cgroup_events,
249 &perf_time_to_tsc,
250 &dlfilter,
251 NULL,
252};
253
254static struct test **tests[] = {
192 generic_tests,
193 arch_tests,
194};
195
196static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[])
197{
198 int i;
199

--- 64 unchanged lines hidden (view full) ---

264 err = -1;
265 pr_debug("test child interrupted\n");
266 }
267 }
268
269 return err;
270}
271
255 generic_tests,
256 arch_tests,
257};
258
259static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[])
260{
261 int i;
262

--- 64 unchanged lines hidden (view full) ---

327 err = -1;
328 pr_debug("test child interrupted\n");
329 }
330 }
331
332 return err;
333}
334
272#define for_each_test(j, t) \
335#define for_each_test(j, k, t) \
273 for (j = 0; j < ARRAY_SIZE(tests); j++) \
336 for (j = 0; j < ARRAY_SIZE(tests); j++) \
274 for (t = &tests[j][0]; t->func; t++)
337 for (k = 0, t = tests[j][k]; tests[j][k]; k++, t = tests[j][k])
275
276static int test_and_print(struct test *t, bool force_skip, int subtest)
277{
278 int err;
279
280 if (!force_skip) {
281 pr_debug("\n--- start ---\n");
282 err = run_test(t, subtest);

--- 182 unchanged lines hidden (view full) ---

465 zfree(&entlist[e]);
466 free(entlist);
467 return 0;
468}
469
470static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
471{
472 struct test *t;
338
339static int test_and_print(struct test *t, bool force_skip, int subtest)
340{
341 int err;
342
343 if (!force_skip) {
344 pr_debug("\n--- start ---\n");
345 err = run_test(t, subtest);

--- 182 unchanged lines hidden (view full) ---

528 zfree(&entlist[e]);
529 free(entlist);
530 return 0;
531}
532
533static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
534{
535 struct test *t;
473 unsigned int j;
536 unsigned int j, k;
474 int i = 0;
475 int width = shell_tests__max_desc_width();
476
537 int i = 0;
538 int width = shell_tests__max_desc_width();
539
477 for_each_test(j, t) {
540 for_each_test(j, k, t) {
478 int len = strlen(t->desc);
479
480 if (width < len)
481 width = len;
482 }
483
541 int len = strlen(t->desc);
542
543 if (width < len)
544 width = len;
545 }
546
484 for_each_test(j, t) {
547 for_each_test(j, k, t) {
485 int curr = i++, err;
486 int subi;
487
488 if (!perf_test__matches(t->desc, curr, argc, argv)) {
489 bool skip = true;
490 int subn;
491
492 if (!t->subtest.get_nr)

--- 99 unchanged lines hidden (view full) ---

592 for (e = 0; e < n_dirs; e++)
593 zfree(&entlist[e]);
594 free(entlist);
595 return 0;
596}
597
598static int perf_test__list(int argc, const char **argv)
599{
548 int curr = i++, err;
549 int subi;
550
551 if (!perf_test__matches(t->desc, curr, argc, argv)) {
552 bool skip = true;
553 int subn;
554
555 if (!t->subtest.get_nr)

--- 99 unchanged lines hidden (view full) ---

655 for (e = 0; e < n_dirs; e++)
656 zfree(&entlist[e]);
657 free(entlist);
658 return 0;
659}
660
661static int perf_test__list(int argc, const char **argv)
662{
600 unsigned int j;
663 unsigned int j, k;
601 struct test *t;
602 int i = 0;
603
664 struct test *t;
665 int i = 0;
666
604 for_each_test(j, t) {
667 for_each_test(j, k, t) {
605 int curr = i++;
606
607 if (!perf_test__matches(t->desc, curr, argc, argv) ||
608 (t->is_supported && !t->is_supported()))
609 continue;
610
611 pr_info("%2d: %s\n", i, t->desc);
612

--- 58 unchanged lines hidden ---
668 int curr = i++;
669
670 if (!perf_test__matches(t->desc, curr, argc, argv) ||
671 (t->is_supported && !t->is_supported()))
672 continue;
673
674 pr_info("%2d: %s\n", i, t->desc);
675

--- 58 unchanged lines hidden ---