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