at master 6.3 kB view raw
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}; 42 43struct 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 */ 105DECLARE_SUITE(vmlinux_matches_kallsyms); 106DECLARE_SUITE(openat_syscall_event); 107DECLARE_SUITE(openat_syscall_event_on_all_cpus); 108DECLARE_SUITE(basic_mmap); 109DECLARE_SUITE(PERF_RECORD); 110DECLARE_SUITE(perf_evsel__roundtrip_name_test); 111DECLARE_SUITE(perf_evsel__tp_sched_test); 112DECLARE_SUITE(syscall_openat_tp_fields); 113DECLARE_SUITE(pmu); 114DECLARE_SUITE(pmu_events); 115DECLARE_SUITE(hwmon_pmu); 116DECLARE_SUITE(tool_pmu); 117DECLARE_SUITE(attr); 118DECLARE_SUITE(dso_data); 119DECLARE_SUITE(dso_data_cache); 120DECLARE_SUITE(dso_data_reopen); 121DECLARE_SUITE(parse_events); 122DECLARE_SUITE(hists_link); 123DECLARE_SUITE(bp_signal); 124DECLARE_SUITE(bp_signal_overflow); 125DECLARE_SUITE(bp_accounting); 126DECLARE_SUITE(wp); 127DECLARE_SUITE(task_exit); 128DECLARE_SUITE(mem); 129DECLARE_SUITE(sw_clock_freq); 130DECLARE_SUITE(code_reading); 131DECLARE_SUITE(sample_parsing); 132DECLARE_SUITE(keep_tracking); 133DECLARE_SUITE(parse_no_sample_id_all); 134DECLARE_SUITE(dwarf_unwind); 135DECLARE_SUITE(expr); 136DECLARE_SUITE(hists_filter); 137DECLARE_SUITE(mmap_thread_lookup); 138DECLARE_SUITE(thread_maps_share); 139DECLARE_SUITE(hists_output); 140DECLARE_SUITE(hists_cumulate); 141DECLARE_SUITE(switch_tracking); 142DECLARE_SUITE(fdarray__filter); 143DECLARE_SUITE(fdarray__add); 144DECLARE_SUITE(kmod_path__parse); 145DECLARE_SUITE(thread_map); 146DECLARE_SUITE(bpf); 147DECLARE_SUITE(session_topology); 148DECLARE_SUITE(thread_map_synthesize); 149DECLARE_SUITE(thread_map_remove); 150DECLARE_SUITE(cpu_map); 151DECLARE_SUITE(synthesize_stat_config); 152DECLARE_SUITE(synthesize_stat); 153DECLARE_SUITE(synthesize_stat_round); 154DECLARE_SUITE(event_update); 155DECLARE_SUITE(event_times); 156DECLARE_SUITE(backward_ring_buffer); 157DECLARE_SUITE(sdt_event); 158DECLARE_SUITE(is_printable_array); 159DECLARE_SUITE(bitmap_print); 160DECLARE_SUITE(perf_hooks); 161DECLARE_SUITE(unit_number__scnprint); 162DECLARE_SUITE(mem2node); 163DECLARE_SUITE(maps); 164DECLARE_SUITE(time_utils); 165DECLARE_SUITE(jit_write_elf); 166DECLARE_SUITE(api_io); 167DECLARE_SUITE(demangle_java); 168DECLARE_SUITE(demangle_ocaml); 169DECLARE_SUITE(demangle_rust); 170DECLARE_SUITE(pfm); 171DECLARE_SUITE(parse_metric); 172DECLARE_SUITE(pe_file_parsing); 173DECLARE_SUITE(expand_cgroup_events); 174DECLARE_SUITE(perf_time_to_tsc); 175DECLARE_SUITE(dlfilter); 176DECLARE_SUITE(sigtrap); 177DECLARE_SUITE(event_groups); 178DECLARE_SUITE(symbols); 179DECLARE_SUITE(util); 180DECLARE_SUITE(subcmd_help); 181DECLARE_SUITE(kallsyms_split); 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 205struct thread; 206struct perf_sample; 207int test__arch_unwind_sample(struct perf_sample *sample, 208 struct thread *thread); 209#endif 210 211#if defined(__arm__) 212DECLARE_SUITE(vectors_page); 213#endif 214 215/* 216 * Define test workloads to be used in test suites. 217 */ 218typedef int (*workload_fnptr)(int argc, const char **argv); 219 220struct 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) \ 229struct test_workload workload__##work = { \ 230 .name = #work, \ 231 .func = work, \ 232} 233 234/* The list of test workloads */ 235DECLARE_WORKLOAD(noploop); 236DECLARE_WORKLOAD(thloop); 237DECLARE_WORKLOAD(leafloop); 238DECLARE_WORKLOAD(sqrtloop); 239DECLARE_WORKLOAD(brstack); 240DECLARE_WORKLOAD(datasym); 241DECLARE_WORKLOAD(landlock); 242DECLARE_WORKLOAD(traploop); 243 244extern const char *dso_to_test; 245extern const char *test_objdump_path; 246 247#endif /* TESTS_H */