tests.h 5.3 KB

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