projects/linux·blob master · refs

260 lines · 6.5 KiB

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