parse-events-test.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. struct test__event_st {
  335. const char *name;
  336. __u32 type;
  337. int (*check)(struct perf_evlist *evlist);
  338. };
  339. static struct test__event_st test__events[] = {
  340. [0] = {
  341. .name = "syscalls:sys_enter_open",
  342. .check = test__checkevent_tracepoint,
  343. },
  344. [1] = {
  345. .name = "syscalls:*",
  346. .check = test__checkevent_tracepoint_multi,
  347. },
  348. [2] = {
  349. .name = "r1a",
  350. .check = test__checkevent_raw,
  351. },
  352. [3] = {
  353. .name = "1:1",
  354. .check = test__checkevent_numeric,
  355. },
  356. [4] = {
  357. .name = "instructions",
  358. .check = test__checkevent_symbolic_name,
  359. },
  360. [5] = {
  361. .name = "cycles/period=100000,config2/",
  362. .check = test__checkevent_symbolic_name_config,
  363. },
  364. [6] = {
  365. .name = "faults",
  366. .check = test__checkevent_symbolic_alias,
  367. },
  368. [7] = {
  369. .name = "L1-dcache-load-miss",
  370. .check = test__checkevent_genhw,
  371. },
  372. [8] = {
  373. .name = "mem:0",
  374. .check = test__checkevent_breakpoint,
  375. },
  376. [9] = {
  377. .name = "mem:0:x",
  378. .check = test__checkevent_breakpoint_x,
  379. },
  380. [10] = {
  381. .name = "mem:0:r",
  382. .check = test__checkevent_breakpoint_r,
  383. },
  384. [11] = {
  385. .name = "mem:0:w",
  386. .check = test__checkevent_breakpoint_w,
  387. },
  388. [12] = {
  389. .name = "syscalls:sys_enter_open:k",
  390. .check = test__checkevent_tracepoint_modifier,
  391. },
  392. [13] = {
  393. .name = "syscalls:*:u",
  394. .check = test__checkevent_tracepoint_multi_modifier,
  395. },
  396. [14] = {
  397. .name = "r1a:kp",
  398. .check = test__checkevent_raw_modifier,
  399. },
  400. [15] = {
  401. .name = "1:1:hp",
  402. .check = test__checkevent_numeric_modifier,
  403. },
  404. [16] = {
  405. .name = "instructions:h",
  406. .check = test__checkevent_symbolic_name_modifier,
  407. },
  408. [17] = {
  409. .name = "faults:u",
  410. .check = test__checkevent_symbolic_alias_modifier,
  411. },
  412. [18] = {
  413. .name = "L1-dcache-load-miss:kp",
  414. .check = test__checkevent_genhw_modifier,
  415. },
  416. [19] = {
  417. .name = "mem:0:u",
  418. .check = test__checkevent_breakpoint_modifier,
  419. },
  420. [20] = {
  421. .name = "mem:0:x:k",
  422. .check = test__checkevent_breakpoint_x_modifier,
  423. },
  424. [21] = {
  425. .name = "mem:0:r:hp",
  426. .check = test__checkevent_breakpoint_r_modifier,
  427. },
  428. [22] = {
  429. .name = "mem:0:w:up",
  430. .check = test__checkevent_breakpoint_w_modifier,
  431. },
  432. [23] = {
  433. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  434. .check = test__checkevent_list,
  435. },
  436. [24] = {
  437. .name = "instructions:G",
  438. .check = test__checkevent_exclude_host_modifier,
  439. },
  440. [25] = {
  441. .name = "instructions:H",
  442. .check = test__checkevent_exclude_guest_modifier,
  443. },
  444. };
  445. #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
  446. static struct test__event_st test__events_pmu[] = {
  447. [0] = {
  448. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  449. .check = test__checkevent_pmu,
  450. },
  451. };
  452. #define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
  453. sizeof(struct test__event_st))
  454. static int test(struct test__event_st *e)
  455. {
  456. struct perf_evlist *evlist;
  457. int ret;
  458. evlist = perf_evlist__new(NULL, NULL);
  459. if (evlist == NULL)
  460. return -ENOMEM;
  461. ret = parse_events(evlist, e->name, 0);
  462. if (ret) {
  463. pr_debug("failed to parse event '%s', err %d\n",
  464. e->name, ret);
  465. return ret;
  466. }
  467. ret = e->check(evlist);
  468. perf_evlist__delete(evlist);
  469. return ret;
  470. }
  471. static int test_events(struct test__event_st *events, unsigned cnt)
  472. {
  473. int ret = 0;
  474. unsigned i;
  475. for (i = 0; i < cnt; i++) {
  476. struct test__event_st *e = &events[i];
  477. pr_debug("running test %d '%s'\n", i, e->name);
  478. ret = test(e);
  479. if (ret)
  480. break;
  481. }
  482. return ret;
  483. }
  484. static int test_pmu(void)
  485. {
  486. struct stat st;
  487. char path[PATH_MAX];
  488. int ret;
  489. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  490. sysfs_find_mountpoint());
  491. ret = stat(path, &st);
  492. if (ret)
  493. pr_debug("ommiting PMU cpu tests\n");
  494. return !ret;
  495. }
  496. int parse_events__test(void)
  497. {
  498. int ret;
  499. ret = test_events(test__events, TEST__EVENTS_CNT);
  500. if (!ret && test_pmu())
  501. ret = test_events(test__events_pmu, TEST__EVENTS_PMU_CNT);
  502. return ret;
  503. }