tests.h 6.3 KB

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