parse-events-test.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. #include "parse-events.h"
  2. #include "evsel.h"
  3. #include "evlist.h"
  4. #include "sysfs.h"
  5. #include "../../../include/linux/hw_breakpoint.h"
  6. #define TEST_ASSERT_VAL(text, cond) \
  7. do { \
  8. if (!(cond)) { \
  9. pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
  10. return -1; \
  11. } \
  12. } while (0)
  13. static int test__checkevent_tracepoint(struct perf_evlist *evlist)
  14. {
  15. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  16. struct perf_evsel, node);
  17. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  18. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  19. TEST_ASSERT_VAL("wrong sample_type",
  20. (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
  21. evsel->attr.sample_type);
  22. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  23. return 0;
  24. }
  25. static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
  26. {
  27. struct perf_evsel *evsel;
  28. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  29. list_for_each_entry(evsel, &evlist->entries, node) {
  30. TEST_ASSERT_VAL("wrong type",
  31. PERF_TYPE_TRACEPOINT == evsel->attr.type);
  32. TEST_ASSERT_VAL("wrong sample_type",
  33. (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU)
  34. == evsel->attr.sample_type);
  35. TEST_ASSERT_VAL("wrong sample_period",
  36. 1 == evsel->attr.sample_period);
  37. }
  38. return 0;
  39. }
  40. static int test__checkevent_raw(struct perf_evlist *evlist)
  41. {
  42. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  43. struct perf_evsel, node);
  44. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  45. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  46. TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
  47. return 0;
  48. }
  49. static int test__checkevent_numeric(struct perf_evlist *evlist)
  50. {
  51. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  52. struct perf_evsel, node);
  53. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  54. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  55. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  56. return 0;
  57. }
  58. static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
  59. {
  60. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  61. struct perf_evsel, node);
  62. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  63. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  64. TEST_ASSERT_VAL("wrong config",
  65. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  66. return 0;
  67. }
  68. static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
  69. {
  70. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  71. struct perf_evsel, node);
  72. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  73. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  74. TEST_ASSERT_VAL("wrong config",
  75. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  76. TEST_ASSERT_VAL("wrong period",
  77. 100000 == evsel->attr.sample_period);
  78. TEST_ASSERT_VAL("wrong config1",
  79. 0 == evsel->attr.config1);
  80. TEST_ASSERT_VAL("wrong config2",
  81. 1 == evsel->attr.config2);
  82. return 0;
  83. }
  84. static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
  85. {
  86. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  87. struct perf_evsel, node);
  88. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  89. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  90. TEST_ASSERT_VAL("wrong config",
  91. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  92. return 0;
  93. }
  94. static int test__checkevent_genhw(struct perf_evlist *evlist)
  95. {
  96. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  97. struct perf_evsel, node);
  98. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  99. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
  100. TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
  101. return 0;
  102. }
  103. static int test__checkevent_breakpoint(struct perf_evlist *evlist)
  104. {
  105. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  106. struct perf_evsel, node);
  107. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  108. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  109. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  110. TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
  111. evsel->attr.bp_type);
  112. TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
  113. evsel->attr.bp_len);
  114. return 0;
  115. }
  116. static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
  117. {
  118. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  119. struct perf_evsel, node);
  120. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  121. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  122. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  123. TEST_ASSERT_VAL("wrong bp_type",
  124. HW_BREAKPOINT_X == evsel->attr.bp_type);
  125. TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
  126. return 0;
  127. }
  128. static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
  129. {
  130. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  131. struct perf_evsel, node);
  132. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  133. TEST_ASSERT_VAL("wrong type",
  134. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  135. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  136. TEST_ASSERT_VAL("wrong bp_type",
  137. HW_BREAKPOINT_R == evsel->attr.bp_type);
  138. TEST_ASSERT_VAL("wrong bp_len",
  139. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  140. return 0;
  141. }
  142. static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
  143. {
  144. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  145. struct perf_evsel, node);
  146. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  147. TEST_ASSERT_VAL("wrong type",
  148. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  149. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  150. TEST_ASSERT_VAL("wrong bp_type",
  151. HW_BREAKPOINT_W == evsel->attr.bp_type);
  152. TEST_ASSERT_VAL("wrong bp_len",
  153. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  154. return 0;
  155. }
  156. static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
  157. {
  158. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  159. struct perf_evsel, node);
  160. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  161. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  162. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  163. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  164. return test__checkevent_tracepoint(evlist);
  165. }
  166. static int
  167. test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
  168. {
  169. struct perf_evsel *evsel;
  170. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  171. list_for_each_entry(evsel, &evlist->entries, node) {
  172. TEST_ASSERT_VAL("wrong exclude_user",
  173. !evsel->attr.exclude_user);
  174. TEST_ASSERT_VAL("wrong exclude_kernel",
  175. evsel->attr.exclude_kernel);
  176. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  177. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  178. }
  179. return test__checkevent_tracepoint_multi(evlist);
  180. }
  181. static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
  182. {
  183. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  184. struct perf_evsel, node);
  185. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  186. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  187. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  188. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  189. return test__checkevent_raw(evlist);
  190. }
  191. static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
  192. {
  193. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  194. struct perf_evsel, node);
  195. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  196. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  197. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  198. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  199. return test__checkevent_numeric(evlist);
  200. }
  201. static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
  202. {
  203. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  204. struct perf_evsel, node);
  205. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  206. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  207. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  208. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  209. return test__checkevent_symbolic_name(evlist);
  210. }
  211. static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
  212. {
  213. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  214. struct perf_evsel, node);
  215. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  216. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  217. return test__checkevent_symbolic_name(evlist);
  218. }
  219. static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
  220. {
  221. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  222. struct perf_evsel, node);
  223. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  224. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  225. return test__checkevent_symbolic_name(evlist);
  226. }
  227. static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
  228. {
  229. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  230. struct perf_evsel, node);
  231. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  232. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  233. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  234. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  235. return test__checkevent_symbolic_alias(evlist);
  236. }
  237. static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
  238. {
  239. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  240. struct perf_evsel, node);
  241. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  242. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  243. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  244. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  245. return test__checkevent_genhw(evlist);
  246. }
  247. static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
  248. {
  249. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  250. struct perf_evsel, node);
  251. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  252. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  253. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  254. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  255. return test__checkevent_breakpoint(evlist);
  256. }
  257. static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
  258. {
  259. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  260. struct perf_evsel, node);
  261. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  262. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  263. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  264. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  265. return test__checkevent_breakpoint_x(evlist);
  266. }
  267. static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
  268. {
  269. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  270. struct perf_evsel, node);
  271. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  272. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  273. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  274. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  275. return test__checkevent_breakpoint_r(evlist);
  276. }
  277. static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
  278. {
  279. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  280. struct perf_evsel, node);
  281. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  282. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  283. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  284. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  285. return test__checkevent_breakpoint_w(evlist);
  286. }
  287. static int test__checkevent_pmu(struct perf_evlist *evlist)
  288. {
  289. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  290. struct perf_evsel, node);
  291. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  292. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  293. TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
  294. TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
  295. TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
  296. TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
  297. return 0;
  298. }
  299. static int test__checkevent_list(struct perf_evlist *evlist)
  300. {
  301. struct perf_evsel *evsel;
  302. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  303. /* r1 */
  304. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  305. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  306. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  307. TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
  308. TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
  309. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  310. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  311. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  312. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  313. /* syscalls:sys_enter_open:k */
  314. evsel = list_entry(evsel->node.next, struct perf_evsel, node);
  315. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  316. TEST_ASSERT_VAL("wrong sample_type",
  317. (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
  318. evsel->attr.sample_type);
  319. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  320. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  321. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  322. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  323. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  324. /* 1:1:hp */
  325. evsel = list_entry(evsel->node.next, struct perf_evsel, node);
  326. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  327. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  328. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  329. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  330. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  331. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  332. return 0;
  333. }
  334. static int test__checkevent_pmu_name(struct perf_evlist *evlist)
  335. {
  336. struct perf_evsel *evsel;
  337. /* cpu/config=1,name=krava1/u */
  338. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  339. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  340. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  341. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  342. TEST_ASSERT_VAL("wrong name", !strcmp(evsel->name, "krava"));
  343. /* cpu/config=2/" */
  344. evsel = list_entry(evsel->node.next, struct perf_evsel, node);
  345. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  346. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  347. TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
  348. TEST_ASSERT_VAL("wrong name", !strcmp(evsel->name, "raw 0x2"));
  349. return 0;
  350. }
  351. struct test__event_st {
  352. const char *name;
  353. __u32 type;
  354. int (*check)(struct perf_evlist *evlist);
  355. };
  356. static struct test__event_st test__events[] = {
  357. [0] = {
  358. .name = "syscalls:sys_enter_open",
  359. .check = test__checkevent_tracepoint,
  360. },
  361. [1] = {
  362. .name = "syscalls:*",
  363. .check = test__checkevent_tracepoint_multi,
  364. },
  365. [2] = {
  366. .name = "r1a",
  367. .check = test__checkevent_raw,
  368. },
  369. [3] = {
  370. .name = "1:1",
  371. .check = test__checkevent_numeric,
  372. },
  373. [4] = {
  374. .name = "instructions",
  375. .check = test__checkevent_symbolic_name,
  376. },
  377. [5] = {
  378. .name = "cycles/period=100000,config2/",
  379. .check = test__checkevent_symbolic_name_config,
  380. },
  381. [6] = {
  382. .name = "faults",
  383. .check = test__checkevent_symbolic_alias,
  384. },
  385. [7] = {
  386. .name = "L1-dcache-load-miss",
  387. .check = test__checkevent_genhw,
  388. },
  389. [8] = {
  390. .name = "mem:0",
  391. .check = test__checkevent_breakpoint,
  392. },
  393. [9] = {
  394. .name = "mem:0:x",
  395. .check = test__checkevent_breakpoint_x,
  396. },
  397. [10] = {
  398. .name = "mem:0:r",
  399. .check = test__checkevent_breakpoint_r,
  400. },
  401. [11] = {
  402. .name = "mem:0:w",
  403. .check = test__checkevent_breakpoint_w,
  404. },
  405. [12] = {
  406. .name = "syscalls:sys_enter_open:k",
  407. .check = test__checkevent_tracepoint_modifier,
  408. },
  409. [13] = {
  410. .name = "syscalls:*:u",
  411. .check = test__checkevent_tracepoint_multi_modifier,
  412. },
  413. [14] = {
  414. .name = "r1a:kp",
  415. .check = test__checkevent_raw_modifier,
  416. },
  417. [15] = {
  418. .name = "1:1:hp",
  419. .check = test__checkevent_numeric_modifier,
  420. },
  421. [16] = {
  422. .name = "instructions:h",
  423. .check = test__checkevent_symbolic_name_modifier,
  424. },
  425. [17] = {
  426. .name = "faults:u",
  427. .check = test__checkevent_symbolic_alias_modifier,
  428. },
  429. [18] = {
  430. .name = "L1-dcache-load-miss:kp",
  431. .check = test__checkevent_genhw_modifier,
  432. },
  433. [19] = {
  434. .name = "mem:0:u",
  435. .check = test__checkevent_breakpoint_modifier,
  436. },
  437. [20] = {
  438. .name = "mem:0:x:k",
  439. .check = test__checkevent_breakpoint_x_modifier,
  440. },
  441. [21] = {
  442. .name = "mem:0:r:hp",
  443. .check = test__checkevent_breakpoint_r_modifier,
  444. },
  445. [22] = {
  446. .name = "mem:0:w:up",
  447. .check = test__checkevent_breakpoint_w_modifier,
  448. },
  449. [23] = {
  450. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  451. .check = test__checkevent_list,
  452. },
  453. [24] = {
  454. .name = "instructions:G",
  455. .check = test__checkevent_exclude_host_modifier,
  456. },
  457. [25] = {
  458. .name = "instructions:H",
  459. .check = test__checkevent_exclude_guest_modifier,
  460. },
  461. };
  462. #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
  463. static struct test__event_st test__events_pmu[] = {
  464. [0] = {
  465. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  466. .check = test__checkevent_pmu,
  467. },
  468. [1] = {
  469. .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
  470. .check = test__checkevent_pmu_name,
  471. },
  472. };
  473. #define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
  474. sizeof(struct test__event_st))
  475. static int test(struct test__event_st *e)
  476. {
  477. struct perf_evlist *evlist;
  478. int ret;
  479. evlist = perf_evlist__new(NULL, NULL);
  480. if (evlist == NULL)
  481. return -ENOMEM;
  482. ret = parse_events(evlist, e->name, 0);
  483. if (ret) {
  484. pr_debug("failed to parse event '%s', err %d\n",
  485. e->name, ret);
  486. return ret;
  487. }
  488. ret = e->check(evlist);
  489. perf_evlist__delete(evlist);
  490. return ret;
  491. }
  492. static int test_events(struct test__event_st *events, unsigned cnt)
  493. {
  494. int ret = 0;
  495. unsigned i;
  496. for (i = 0; i < cnt; i++) {
  497. struct test__event_st *e = &events[i];
  498. pr_debug("running test %d '%s'\n", i, e->name);
  499. ret = test(e);
  500. if (ret)
  501. break;
  502. }
  503. return ret;
  504. }
  505. static int test_pmu(void)
  506. {
  507. struct stat st;
  508. char path[PATH_MAX];
  509. int ret;
  510. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  511. sysfs_find_mountpoint());
  512. ret = stat(path, &st);
  513. if (ret)
  514. pr_debug("ommiting PMU cpu tests\n");
  515. return !ret;
  516. }
  517. int parse_events__test(void)
  518. {
  519. int ret;
  520. ret = test_events(test__events, TEST__EVENTS_CNT);
  521. if (!ret && test_pmu())
  522. ret = test_events(test__events_pmu, TEST__EVENTS_PMU_CNT);
  523. return ret;
  524. }