xref: /linux/tools/perf/tests/tests.h (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
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 };
42 
43 struct test_suite {
44 	const char *desc;
45 	struct test_case *test_cases;
46 	void *priv;
47 };
48 
49 #define DECLARE_SUITE(name) \
50 	extern struct test_suite suite__##name;
51 
52 #define TEST_CASE(description, _name)			\
53 	{						\
54 		.name = #_name,				\
55 		.desc = description,			\
56 		.run_case = test__##_name,		\
57 	}
58 
59 #define TEST_CASE_REASON(description, _name, _reason)	\
60 	{						\
61 		.name = #_name,				\
62 		.desc = description,			\
63 		.run_case = test__##_name,		\
64 		.skip_reason = _reason,			\
65 	}
66 
67 #define TEST_CASE_EXCLUSIVE(description, _name)		\
68 	{						\
69 		.name = #_name,				\
70 		.desc = description,			\
71 		.run_case = test__##_name,		\
72 		.exclusive = true,			\
73 	}
74 
75 #define TEST_CASE_REASON_EXCLUSIVE(description, _name, _reason)	\
76 	{						\
77 		.name = #_name,				\
78 		.desc = description,			\
79 		.run_case = test__##_name,		\
80 		.skip_reason = _reason,			\
81 		.exclusive = true,			\
82 	}
83 
84 #define DEFINE_SUITE(description, _name)		\
85 	struct test_case tests__##_name[] = {           \
86 		TEST_CASE(description, _name),		\
87 		{	.name = NULL, }			\
88 	};						\
89 	struct test_suite suite__##_name = {		\
90 		.desc = description,			\
91 		.test_cases = tests__##_name,		\
92 	}
93 
94 #define DEFINE_SUITE_EXCLUSIVE(description, _name)	\
95 	struct test_case tests__##_name[] = {           \
96 		TEST_CASE_EXCLUSIVE(description, _name),\
97 		{	.name = NULL, }			\
98 	};						\
99 	struct test_suite suite__##_name = {		\
100 		.desc = description,			\
101 		.test_cases = tests__##_name,		\
102 	}
103 
104 /* Tests */
105 DECLARE_SUITE(vmlinux_matches_kallsyms);
106 DECLARE_SUITE(openat_syscall_event);
107 DECLARE_SUITE(openat_syscall_event_on_all_cpus);
108 DECLARE_SUITE(basic_mmap);
109 DECLARE_SUITE(PERF_RECORD);
110 DECLARE_SUITE(perf_evsel__roundtrip_name_test);
111 DECLARE_SUITE(perf_evsel__tp_sched_test);
112 DECLARE_SUITE(syscall_openat_tp_fields);
113 DECLARE_SUITE(pmu);
114 DECLARE_SUITE(pmu_events);
115 DECLARE_SUITE(hwmon_pmu);
116 DECLARE_SUITE(tool_pmu);
117 DECLARE_SUITE(attr);
118 DECLARE_SUITE(dso_data);
119 DECLARE_SUITE(dso_data_cache);
120 DECLARE_SUITE(dso_data_reopen);
121 DECLARE_SUITE(parse_events);
122 DECLARE_SUITE(hists_link);
123 DECLARE_SUITE(python_use);
124 DECLARE_SUITE(bp_signal);
125 DECLARE_SUITE(bp_signal_overflow);
126 DECLARE_SUITE(bp_accounting);
127 DECLARE_SUITE(wp);
128 DECLARE_SUITE(task_exit);
129 DECLARE_SUITE(mem);
130 DECLARE_SUITE(sw_clock_freq);
131 DECLARE_SUITE(code_reading);
132 DECLARE_SUITE(sample_parsing);
133 DECLARE_SUITE(keep_tracking);
134 DECLARE_SUITE(parse_no_sample_id_all);
135 DECLARE_SUITE(dwarf_unwind);
136 DECLARE_SUITE(expr);
137 DECLARE_SUITE(hists_filter);
138 DECLARE_SUITE(mmap_thread_lookup);
139 DECLARE_SUITE(thread_maps_share);
140 DECLARE_SUITE(hists_output);
141 DECLARE_SUITE(hists_cumulate);
142 DECLARE_SUITE(switch_tracking);
143 DECLARE_SUITE(fdarray__filter);
144 DECLARE_SUITE(fdarray__add);
145 DECLARE_SUITE(kmod_path__parse);
146 DECLARE_SUITE(thread_map);
147 DECLARE_SUITE(bpf);
148 DECLARE_SUITE(session_topology);
149 DECLARE_SUITE(thread_map_synthesize);
150 DECLARE_SUITE(thread_map_remove);
151 DECLARE_SUITE(cpu_map);
152 DECLARE_SUITE(synthesize_stat_config);
153 DECLARE_SUITE(synthesize_stat);
154 DECLARE_SUITE(synthesize_stat_round);
155 DECLARE_SUITE(event_update);
156 DECLARE_SUITE(event_times);
157 DECLARE_SUITE(backward_ring_buffer);
158 DECLARE_SUITE(sdt_event);
159 DECLARE_SUITE(is_printable_array);
160 DECLARE_SUITE(bitmap_print);
161 DECLARE_SUITE(perf_hooks);
162 DECLARE_SUITE(unit_number__scnprint);
163 DECLARE_SUITE(mem2node);
164 DECLARE_SUITE(maps__merge_in);
165 DECLARE_SUITE(time_utils);
166 DECLARE_SUITE(jit_write_elf);
167 DECLARE_SUITE(api_io);
168 DECLARE_SUITE(demangle_java);
169 DECLARE_SUITE(demangle_ocaml);
170 DECLARE_SUITE(demangle_rust);
171 DECLARE_SUITE(pfm);
172 DECLARE_SUITE(parse_metric);
173 DECLARE_SUITE(pe_file_parsing);
174 DECLARE_SUITE(expand_cgroup_events);
175 DECLARE_SUITE(perf_time_to_tsc);
176 DECLARE_SUITE(dlfilter);
177 DECLARE_SUITE(sigtrap);
178 DECLARE_SUITE(event_groups);
179 DECLARE_SUITE(symbols);
180 DECLARE_SUITE(util);
181 DECLARE_SUITE(subcmd_help);
182 
183 /*
184  * PowerPC and S390 do not support creation of instruction breakpoints using the
185  * perf_event interface.
186  *
187  * ARM requires explicit rounding down of the instruction pointer in Thumb mode,
188  * and then requires the single-step to be handled explicitly in the overflow
189  * handler to avoid stepping into the SIGIO handler and getting stuck on the
190  * breakpointed instruction.
191  *
192  * Since arm64 has the same issue with arm for the single-step handling, this
193  * case also gets stuck on the breakpointed instruction.
194  *
195  * Just disable the test for these architectures until these issues are
196  * resolved.
197  */
198 #if defined(__powerpc__) || defined(__s390x__) || defined(__arm__) || defined(__aarch64__)
199 #define BP_SIGNAL_IS_SUPPORTED 0
200 #else
201 #define BP_SIGNAL_IS_SUPPORTED 1
202 #endif
203 
204 #ifdef HAVE_DWARF_UNWIND_SUPPORT
205 struct thread;
206 struct perf_sample;
207 int test__arch_unwind_sample(struct perf_sample *sample,
208 			     struct thread *thread);
209 #endif
210 
211 #if defined(__arm__)
212 DECLARE_SUITE(vectors_page);
213 #endif
214 
215 /*
216  * Define test workloads to be used in test suites.
217  */
218 typedef int (*workload_fnptr)(int argc, const char **argv);
219 
220 struct test_workload {
221 	const char	*name;
222 	workload_fnptr	func;
223 };
224 
225 #define DECLARE_WORKLOAD(work) \
226 	extern struct test_workload workload__##work
227 
228 #define DEFINE_WORKLOAD(work) \
229 struct test_workload workload__##work = {	\
230 	.name = #work,				\
231 	.func = work,				\
232 }
233 
234 /* The list of test workloads */
235 DECLARE_WORKLOAD(noploop);
236 DECLARE_WORKLOAD(thloop);
237 DECLARE_WORKLOAD(leafloop);
238 DECLARE_WORKLOAD(sqrtloop);
239 DECLARE_WORKLOAD(brstack);
240 DECLARE_WORKLOAD(datasym);
241 DECLARE_WORKLOAD(landlock);
242 
243 extern const char *dso_to_test;
244 extern const char *test_objdump_path;
245 
246 #endif /* TESTS_H */
247