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