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(bp_signal); 124 DECLARE_SUITE(bp_signal_overflow); 125 DECLARE_SUITE(bp_accounting); 126 DECLARE_SUITE(wp); 127 DECLARE_SUITE(task_exit); 128 DECLARE_SUITE(mem); 129 DECLARE_SUITE(sw_clock_freq); 130 DECLARE_SUITE(code_reading); 131 DECLARE_SUITE(sample_parsing); 132 DECLARE_SUITE(keep_tracking); 133 DECLARE_SUITE(parse_no_sample_id_all); 134 DECLARE_SUITE(dwarf_unwind); 135 DECLARE_SUITE(expr); 136 DECLARE_SUITE(hists_filter); 137 DECLARE_SUITE(mmap_thread_lookup); 138 DECLARE_SUITE(thread_maps_share); 139 DECLARE_SUITE(hists_output); 140 DECLARE_SUITE(hists_cumulate); 141 DECLARE_SUITE(switch_tracking); 142 DECLARE_SUITE(fdarray__filter); 143 DECLARE_SUITE(fdarray__add); 144 DECLARE_SUITE(kmod_path__parse); 145 DECLARE_SUITE(thread_map); 146 DECLARE_SUITE(bpf); 147 DECLARE_SUITE(session_topology); 148 DECLARE_SUITE(thread_map_synthesize); 149 DECLARE_SUITE(thread_map_remove); 150 DECLARE_SUITE(cpu_map); 151 DECLARE_SUITE(synthesize_stat_config); 152 DECLARE_SUITE(synthesize_stat); 153 DECLARE_SUITE(synthesize_stat_round); 154 DECLARE_SUITE(event_update); 155 DECLARE_SUITE(event_times); 156 DECLARE_SUITE(backward_ring_buffer); 157 DECLARE_SUITE(sdt_event); 158 DECLARE_SUITE(is_printable_array); 159 DECLARE_SUITE(bitmap_print); 160 DECLARE_SUITE(perf_hooks); 161 DECLARE_SUITE(unit_number__scnprint); 162 DECLARE_SUITE(mem2node); 163 DECLARE_SUITE(maps__merge_in); 164 DECLARE_SUITE(time_utils); 165 DECLARE_SUITE(jit_write_elf); 166 DECLARE_SUITE(api_io); 167 DECLARE_SUITE(demangle_java); 168 DECLARE_SUITE(demangle_ocaml); 169 DECLARE_SUITE(demangle_rust); 170 DECLARE_SUITE(pfm); 171 DECLARE_SUITE(parse_metric); 172 DECLARE_SUITE(pe_file_parsing); 173 DECLARE_SUITE(expand_cgroup_events); 174 DECLARE_SUITE(perf_time_to_tsc); 175 DECLARE_SUITE(dlfilter); 176 DECLARE_SUITE(sigtrap); 177 DECLARE_SUITE(event_groups); 178 DECLARE_SUITE(symbols); 179 DECLARE_SUITE(util); 180 DECLARE_SUITE(subcmd_help); 181 182 /* 183 * PowerPC and S390 do not support creation of instruction breakpoints using the 184 * perf_event interface. 185 * 186 * ARM requires explicit rounding down of the instruction pointer in Thumb mode, 187 * and then requires the single-step to be handled explicitly in the overflow 188 * handler to avoid stepping into the SIGIO handler and getting stuck on the 189 * breakpointed instruction. 190 * 191 * Since arm64 has the same issue with arm for the single-step handling, this 192 * case also gets stuck on the breakpointed instruction. 193 * 194 * Just disable the test for these architectures until these issues are 195 * resolved. 196 */ 197 #if defined(__powerpc__) || defined(__s390x__) || defined(__arm__) || defined(__aarch64__) 198 #define BP_SIGNAL_IS_SUPPORTED 0 199 #else 200 #define BP_SIGNAL_IS_SUPPORTED 1 201 #endif 202 203 #ifdef HAVE_DWARF_UNWIND_SUPPORT 204 struct thread; 205 struct perf_sample; 206 int test__arch_unwind_sample(struct perf_sample *sample, 207 struct thread *thread); 208 #endif 209 210 #if defined(__arm__) 211 DECLARE_SUITE(vectors_page); 212 #endif 213 214 /* 215 * Define test workloads to be used in test suites. 216 */ 217 typedef int (*workload_fnptr)(int argc, const char **argv); 218 219 struct test_workload { 220 const char *name; 221 workload_fnptr func; 222 }; 223 224 #define DECLARE_WORKLOAD(work) \ 225 extern struct test_workload workload__##work 226 227 #define DEFINE_WORKLOAD(work) \ 228 struct test_workload workload__##work = { \ 229 .name = #work, \ 230 .func = work, \ 231 } 232 233 /* The list of test workloads */ 234 DECLARE_WORKLOAD(noploop); 235 DECLARE_WORKLOAD(thloop); 236 DECLARE_WORKLOAD(leafloop); 237 DECLARE_WORKLOAD(sqrtloop); 238 DECLARE_WORKLOAD(brstack); 239 DECLARE_WORKLOAD(datasym); 240 DECLARE_WORKLOAD(landlock); 241 DECLARE_WORKLOAD(traploop); 242 243 extern const char *dso_to_test; 244 extern const char *test_objdump_path; 245 246 #endif /* TESTS_H */ 247