xref: /openbmc/linux/tools/perf/tests/tests.h (revision 848ddf5999d224050f6cde8c165630fd7671085f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef TESTS_H
3 #define TESTS_H
4 
5 #include <stdbool.h>
6 
7 #define TEST_ASSERT_VAL(text, cond)					 \
8 do {									 \
9 	if (!(cond)) {							 \
10 		pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
11 		return -1;						 \
12 	}								 \
13 } while (0)
14 
15 #define TEST_ASSERT_EQUAL(text, val, expected)				 \
16 do {									 \
17 	if (val != expected) {						 \
18 		pr_debug("FAILED %s:%d %s (%d != %d)\n",		 \
19 			 __FILE__, __LINE__, text, val, expected);	 \
20 		return -1;						 \
21 	}								 \
22 } while (0)
23 
24 enum {
25 	TEST_OK   =  0,
26 	TEST_FAIL = -1,
27 	TEST_SKIP = -2,
28 };
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 };
40 
41 struct test_suite {
42 	const char *desc;
43 	struct {
44 		bool skip_if_fail;
45 	} subtest;
46 	struct test_case *test_cases;
47 	void *priv;
48 };
49 
50 #define DECLARE_SUITE(name) \
51 	extern struct test_suite suite__##name;
52 
53 #define TEST_CASE(description, _name)			\
54 	{						\
55 		.name = #_name,				\
56 		.desc = description,			\
57 		.run_case = test__##_name,		\
58 	}
59 
60 #define TEST_CASE_REASON(description, _name, _reason)	\
61 	{						\
62 		.name = #_name,				\
63 		.desc = description,			\
64 		.run_case = test__##_name,		\
65 		.skip_reason = _reason,			\
66 	}
67 
68 #define DEFINE_SUITE(description, _name)		\
69 	struct test_case tests__##_name[] = {           \
70 		TEST_CASE(description, _name),		\
71 		{	.name = NULL, }			\
72 	};						\
73 	struct test_suite suite__##_name = {		\
74 		.desc = description,			\
75 		.test_cases = tests__##_name,		\
76 	}
77 
78 /* Tests */
79 DECLARE_SUITE(vmlinux_matches_kallsyms);
80 DECLARE_SUITE(openat_syscall_event);
81 DECLARE_SUITE(openat_syscall_event_on_all_cpus);
82 DECLARE_SUITE(basic_mmap);
83 DECLARE_SUITE(PERF_RECORD);
84 DECLARE_SUITE(perf_evsel__roundtrip_name_test);
85 DECLARE_SUITE(perf_evsel__tp_sched_test);
86 DECLARE_SUITE(syscall_openat_tp_fields);
87 DECLARE_SUITE(pmu);
88 DECLARE_SUITE(pmu_events);
89 DECLARE_SUITE(attr);
90 DECLARE_SUITE(dso_data);
91 DECLARE_SUITE(dso_data_cache);
92 DECLARE_SUITE(dso_data_reopen);
93 DECLARE_SUITE(parse_events);
94 DECLARE_SUITE(hists_link);
95 DECLARE_SUITE(python_use);
96 DECLARE_SUITE(bp_signal);
97 DECLARE_SUITE(bp_signal_overflow);
98 DECLARE_SUITE(bp_accounting);
99 DECLARE_SUITE(wp);
100 DECLARE_SUITE(task_exit);
101 DECLARE_SUITE(mem);
102 DECLARE_SUITE(sw_clock_freq);
103 DECLARE_SUITE(code_reading);
104 DECLARE_SUITE(sample_parsing);
105 DECLARE_SUITE(keep_tracking);
106 DECLARE_SUITE(parse_no_sample_id_all);
107 DECLARE_SUITE(dwarf_unwind);
108 DECLARE_SUITE(expr);
109 DECLARE_SUITE(hists_filter);
110 DECLARE_SUITE(mmap_thread_lookup);
111 DECLARE_SUITE(thread_maps_share);
112 DECLARE_SUITE(hists_output);
113 DECLARE_SUITE(hists_cumulate);
114 DECLARE_SUITE(switch_tracking);
115 DECLARE_SUITE(fdarray__filter);
116 DECLARE_SUITE(fdarray__add);
117 DECLARE_SUITE(kmod_path__parse);
118 DECLARE_SUITE(thread_map);
119 DECLARE_SUITE(llvm);
120 DECLARE_SUITE(bpf);
121 DECLARE_SUITE(session_topology);
122 DECLARE_SUITE(thread_map_synthesize);
123 DECLARE_SUITE(thread_map_remove);
124 DECLARE_SUITE(cpu_map_synthesize);
125 DECLARE_SUITE(synthesize_stat_config);
126 DECLARE_SUITE(synthesize_stat);
127 DECLARE_SUITE(synthesize_stat_round);
128 DECLARE_SUITE(event_update);
129 DECLARE_SUITE(event_times);
130 DECLARE_SUITE(backward_ring_buffer);
131 DECLARE_SUITE(cpu_map_print);
132 DECLARE_SUITE(cpu_map_merge);
133 DECLARE_SUITE(sdt_event);
134 DECLARE_SUITE(is_printable_array);
135 DECLARE_SUITE(bitmap_print);
136 DECLARE_SUITE(perf_hooks);
137 DECLARE_SUITE(clang);
138 DECLARE_SUITE(unit_number__scnprint);
139 DECLARE_SUITE(mem2node);
140 DECLARE_SUITE(maps__merge_in);
141 DECLARE_SUITE(time_utils);
142 DECLARE_SUITE(jit_write_elf);
143 DECLARE_SUITE(api_io);
144 DECLARE_SUITE(demangle_java);
145 DECLARE_SUITE(demangle_ocaml);
146 DECLARE_SUITE(pfm);
147 DECLARE_SUITE(parse_metric);
148 DECLARE_SUITE(pe_file_parsing);
149 DECLARE_SUITE(expand_cgroup_events);
150 DECLARE_SUITE(perf_time_to_tsc);
151 DECLARE_SUITE(dlfilter);
152 
153 /*
154  * PowerPC and S390 do not support creation of instruction breakpoints using the
155  * perf_event interface.
156  *
157  * ARM requires explicit rounding down of the instruction pointer in Thumb mode,
158  * and then requires the single-step to be handled explicitly in the overflow
159  * handler to avoid stepping into the SIGIO handler and getting stuck on the
160  * breakpointed instruction.
161  *
162  * Since arm64 has the same issue with arm for the single-step handling, this
163  * case also gets stuck on the breakpointed instruction.
164  *
165  * Just disable the test for these architectures until these issues are
166  * resolved.
167  */
168 #if defined(__powerpc__) || defined(__s390x__) || defined(__arm__) || defined(__aarch64__)
169 #define BP_SIGNAL_IS_SUPPORTED 0
170 #else
171 #define BP_SIGNAL_IS_SUPPORTED 1
172 #endif
173 
174 #ifdef HAVE_DWARF_UNWIND_SUPPORT
175 struct thread;
176 struct perf_sample;
177 int test__arch_unwind_sample(struct perf_sample *sample,
178 			     struct thread *thread);
179 #endif
180 
181 #if defined(__arm__)
182 DECLARE_SUITE(vectors_page);
183 #endif
184 
185 #endif /* TESTS_H */
186