xref: /linux/tools/perf/tests/tests.h (revision 3dabc8ad8ae024101dd0cfd42fd72df8817622f5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef TESTS_H
3 #define TESTS_H
4 
5 #include <stdbool.h>
6 #include "util/debug.h"
7 
8 enum {
9 	TEST_OK   =  0,
10 	TEST_FAIL = -1,
11 	TEST_SKIP = -2,
12 };
13 
14 #define TEST_ASSERT_VAL(text, cond)					 \
15 do {									 \
16 	if (!(cond)) {							 \
17 		pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
18 		return TEST_FAIL;					 \
19 	}								 \
20 } while (0)
21 
22 #define TEST_ASSERT_EQUAL(text, val, expected)				 \
23 do {									 \
24 	if (val != expected) {						 \
25 		pr_debug("FAILED %s:%d %s (%d != %d)\n",		 \
26 			 __FILE__, __LINE__, text, val, expected);	 \
27 		return TEST_FAIL;						 \
28 	}								 \
29 } while (0)
30 
31 struct test_suite;
32 
33 typedef int (*test_fnptr)(struct test_suite *, int);
34 
35 struct test_case {
36 	const char *name;
37 	const char *desc;
38 	const char *skip_reason;
39 	test_fnptr run_case;
40 	bool exclusive;
41 	void *priv;
42 };
43 
44 struct test_suite {
45 	const char *desc;
46 	struct test_case *test_cases;
47 	void *priv;
48 	int (*setup)(struct test_suite *suite);
49 	/*
50 	 * Set for the suites mapping perf ring buffers, that need room in the
51 	 * per user budget set in kernel.perf_event_mlock_kb, see
52 	 * shell_test__requisites() for the shell suites.
53 	 */
54 	bool needs_mlock;
55 };
56 
57 #define DECLARE_SUITE(name) \
58 	extern struct test_suite suite__##name;
59 
60 #define TEST_CASE(description, _name)			\
61 	{						\
62 		.name = #_name,				\
63 		.desc = description,			\
64 		.run_case = test__##_name,		\
65 	}
66 
67 #define TEST_CASE_REASON(description, _name, _reason)	\
68 	{						\
69 		.name = #_name,				\
70 		.desc = description,			\
71 		.run_case = test__##_name,		\
72 		.skip_reason = _reason,			\
73 	}
74 
75 #define TEST_CASE_EXCLUSIVE(description, _name)		\
76 	{						\
77 		.name = #_name,				\
78 		.desc = description,			\
79 		.run_case = test__##_name,		\
80 		.exclusive = true,			\
81 	}
82 
83 #define TEST_CASE_REASON_EXCLUSIVE(description, _name, _reason)	\
84 	{						\
85 		.name = #_name,				\
86 		.desc = description,			\
87 		.run_case = test__##_name,		\
88 		.skip_reason = _reason,			\
89 		.exclusive = true,			\
90 	}
91 
92 #define DEFINE_SUITE(description, _name)		\
93 	struct test_case tests__##_name[] = {           \
94 		TEST_CASE(description, _name),		\
95 		{	.name = NULL, }			\
96 	};						\
97 	struct test_suite suite__##_name = {		\
98 		.desc = description,			\
99 		.test_cases = tests__##_name,		\
100 	}
101 
102 #define DEFINE_SUITE_EXCLUSIVE(description, _name)	\
103 	struct test_case tests__##_name[] = {           \
104 		TEST_CASE_EXCLUSIVE(description, _name),\
105 		{	.name = NULL, }			\
106 	};						\
107 	struct test_suite suite__##_name = {		\
108 		.desc = description,			\
109 		.test_cases = tests__##_name,		\
110 	}
111 
112 #define DEFINE_SUITE_NEEDS_MLOCK(description, _name)	\
113 	struct test_case tests__##_name[] = {           \
114 		TEST_CASE(description, _name),		\
115 		{	.name = NULL, }			\
116 	};						\
117 	struct test_suite suite__##_name = {		\
118 		.desc = description,			\
119 		.test_cases = tests__##_name,		\
120 		.needs_mlock = true,			\
121 	}
122 
123 /* Tests */
124 DECLARE_SUITE(vmlinux_matches_kallsyms);
125 DECLARE_SUITE(openat_syscall_event);
126 DECLARE_SUITE(openat_syscall_event_on_all_cpus);
127 DECLARE_SUITE(basic_mmap);
128 DECLARE_SUITE(PERF_RECORD);
129 DECLARE_SUITE(perf_evsel__roundtrip_name_test);
130 DECLARE_SUITE(perf_evsel__tp_sched_test);
131 DECLARE_SUITE(syscall_openat_tp_fields);
132 DECLARE_SUITE(pmu);
133 DECLARE_SUITE(pmu_events);
134 DECLARE_SUITE(hwmon_pmu);
135 DECLARE_SUITE(tool_pmu);
136 DECLARE_SUITE(attr);
137 DECLARE_SUITE(dso_data);
138 DECLARE_SUITE(dso_data_cache);
139 DECLARE_SUITE(dso_data_reopen);
140 DECLARE_SUITE(parse_events);
141 DECLARE_SUITE(hists_link);
142 DECLARE_SUITE(bp_signal);
143 DECLARE_SUITE(bp_signal_overflow);
144 DECLARE_SUITE(event_refresh);
145 DECLARE_SUITE(bp_accounting);
146 DECLARE_SUITE(wp);
147 DECLARE_SUITE(task_exit);
148 DECLARE_SUITE(mem);
149 DECLARE_SUITE(sw_clock_freq);
150 DECLARE_SUITE(code_reading);
151 DECLARE_SUITE(sample_parsing);
152 DECLARE_SUITE(keep_tracking);
153 DECLARE_SUITE(parse_no_sample_id_all);
154 DECLARE_SUITE(dwarf_unwind);
155 DECLARE_SUITE(expr);
156 DECLARE_SUITE(hists_filter);
157 DECLARE_SUITE(mmap_thread_lookup);
158 DECLARE_SUITE(thread_maps_share);
159 DECLARE_SUITE(hists_output);
160 DECLARE_SUITE(hists_cumulate);
161 DECLARE_SUITE(switch_tracking);
162 DECLARE_SUITE(fdarray__filter);
163 DECLARE_SUITE(fdarray__add);
164 DECLARE_SUITE(kmod_path__parse);
165 DECLARE_SUITE(thread_map);
166 DECLARE_SUITE(bpf);
167 DECLARE_SUITE(session_topology);
168 DECLARE_SUITE(thread_map_synthesize);
169 DECLARE_SUITE(thread_map_remove);
170 DECLARE_SUITE(cpu_map);
171 DECLARE_SUITE(synthesize_stat_config);
172 DECLARE_SUITE(synthesize_stat);
173 DECLARE_SUITE(synthesize_stat_round);
174 DECLARE_SUITE(event_update);
175 DECLARE_SUITE(event_times);
176 DECLARE_SUITE(backward_ring_buffer);
177 DECLARE_SUITE(sdt_event);
178 DECLARE_SUITE(is_printable_array);
179 DECLARE_SUITE(bitmap_print);
180 DECLARE_SUITE(perf_hooks);
181 DECLARE_SUITE(unit_number__scnprint);
182 DECLARE_SUITE(mem2node);
183 DECLARE_SUITE(maps);
184 DECLARE_SUITE(time_utils);
185 DECLARE_SUITE(jit_write_elf);
186 DECLARE_SUITE(api_io);
187 DECLARE_SUITE(demangle_java);
188 DECLARE_SUITE(demangle_ocaml);
189 DECLARE_SUITE(demangle_rust);
190 DECLARE_SUITE(pfm);
191 DECLARE_SUITE(parse_metric);
192 DECLARE_SUITE(pe_file_parsing);
193 DECLARE_SUITE(expand_cgroup_events);
194 DECLARE_SUITE(perf_time_to_tsc);
195 DECLARE_SUITE(dlfilter);
196 DECLARE_SUITE(sigtrap);
197 DECLARE_SUITE(event_groups);
198 DECLARE_SUITE(hybrid_merge);
199 DECLARE_SUITE(symbols);
200 DECLARE_SUITE(util);
201 DECLARE_SUITE(uncore_event_sorting);
202 DECLARE_SUITE(subcmd_help);
203 DECLARE_SUITE(kallsyms_split);
204 
205 /*
206  * PowerPC and S390 do not support creation of instruction breakpoints using the
207  * perf_event interface.
208  *
209  * ARM requires explicit rounding down of the instruction pointer in Thumb mode,
210  * and then requires the single-step to be handled explicitly in the overflow
211  * handler to avoid stepping into the SIGIO handler and getting stuck on the
212  * breakpointed instruction.
213  *
214  * Since arm64 has the same issue with arm for the single-step handling, this
215  * case also gets stuck on the breakpointed instruction.
216  *
217  * Just disable the test for these architectures until these issues are
218  * resolved.
219  */
220 #if defined(__powerpc__) || defined(__s390x__) || defined(__arm__) || defined(__aarch64__)
221 #define BP_SIGNAL_IS_SUPPORTED 0
222 #else
223 #define BP_SIGNAL_IS_SUPPORTED 1
224 #endif
225 
226 #ifdef HAVE_DWARF_UNWIND_SUPPORT
227 struct thread;
228 struct perf_sample;
229 int test__arch_unwind_sample(struct perf_sample *sample,
230 			     struct thread *thread);
231 #endif
232 
233 #if defined(__arm__)
234 DECLARE_SUITE(vectors_page);
235 #endif
236 
237 /*
238  * Define test workloads to be used in test suites.
239  */
240 typedef int (*workload_fnptr)(int argc, const char **argv);
241 
242 struct test_workload {
243 	const char	*name;
244 	workload_fnptr	func;
245 };
246 
247 #define DECLARE_WORKLOAD(work) \
248 	extern struct test_workload workload__##work
249 
250 #define DEFINE_WORKLOAD(work) \
251 struct test_workload workload__##work = {	\
252 	.name = #work,				\
253 	.func = work,				\
254 }
255 
256 /* The list of test workloads */
257 DECLARE_WORKLOAD(noploop);
258 DECLARE_WORKLOAD(thloop);
259 DECLARE_WORKLOAD(named_threads);
260 DECLARE_WORKLOAD(leafloop);
261 DECLARE_WORKLOAD(sqrtloop);
262 DECLARE_WORKLOAD(brstack);
263 DECLARE_WORKLOAD(datasym);
264 DECLARE_WORKLOAD(landlock);
265 DECLARE_WORKLOAD(traploop);
266 DECLARE_WORKLOAD(inlineloop);
267 DECLARE_WORKLOAD(jitdump);
268 DECLARE_WORKLOAD(context_switch_loop);
269 DECLARE_WORKLOAD(deterministic);
270 DECLARE_WORKLOAD(callchain);
271 DECLARE_WORKLOAD(false_sharing);
272 
273 #ifdef HAVE_RUST_SUPPORT
274 DECLARE_WORKLOAD(code_with_type);
275 #endif
276 
277 extern const char *dso_to_test;
278 extern const char *test_objdump_path;
279 
280 #endif /* TESTS_H */
281