parse-events-test.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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_breakpoint_rw(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 number of entries", 1 == evlist->nr_entries);
  161. TEST_ASSERT_VAL("wrong type",
  162. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  163. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  164. TEST_ASSERT_VAL("wrong bp_type",
  165. (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
  166. TEST_ASSERT_VAL("wrong bp_len",
  167. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  168. return 0;
  169. }
  170. static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
  171. {
  172. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  173. struct perf_evsel, node);
  174. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  175. TEST_ASSERT_VAL("wrong exclude_kernel", !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. return test__checkevent_tracepoint(evlist);
  179. }
  180. static int
  181. test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
  182. {
  183. struct perf_evsel *evsel;
  184. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  185. list_for_each_entry(evsel, &evlist->entries, node) {
  186. TEST_ASSERT_VAL("wrong exclude_user",
  187. !evsel->attr.exclude_user);
  188. TEST_ASSERT_VAL("wrong exclude_kernel",
  189. evsel->attr.exclude_kernel);
  190. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  191. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  192. }
  193. return test__checkevent_tracepoint_multi(evlist);
  194. }
  195. static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
  196. {
  197. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  198. struct perf_evsel, node);
  199. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  200. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  201. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  202. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  203. return test__checkevent_raw(evlist);
  204. }
  205. static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
  206. {
  207. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  208. struct perf_evsel, node);
  209. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  210. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  211. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  212. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  213. return test__checkevent_numeric(evlist);
  214. }
  215. static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
  216. {
  217. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  218. struct perf_evsel, node);
  219. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  220. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  221. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  222. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  223. return test__checkevent_symbolic_name(evlist);
  224. }
  225. static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
  226. {
  227. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  228. struct perf_evsel, node);
  229. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  230. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  231. return test__checkevent_symbolic_name(evlist);
  232. }
  233. static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
  234. {
  235. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  236. struct perf_evsel, node);
  237. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  238. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  239. return test__checkevent_symbolic_name(evlist);
  240. }
  241. static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
  242. {
  243. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  244. struct perf_evsel, node);
  245. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  246. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  247. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  248. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  249. return test__checkevent_symbolic_alias(evlist);
  250. }
  251. static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
  252. {
  253. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  254. struct perf_evsel, node);
  255. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  256. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  257. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  258. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  259. return test__checkevent_genhw(evlist);
  260. }
  261. static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
  262. {
  263. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  264. struct perf_evsel, node);
  265. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  266. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  267. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  268. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  269. return test__checkevent_breakpoint(evlist);
  270. }
  271. static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
  272. {
  273. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  274. struct perf_evsel, node);
  275. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  276. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  277. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  278. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  279. return test__checkevent_breakpoint_x(evlist);
  280. }
  281. static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
  282. {
  283. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  284. struct perf_evsel, node);
  285. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  286. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  287. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  288. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  289. return test__checkevent_breakpoint_r(evlist);
  290. }
  291. static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
  292. {
  293. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  294. struct perf_evsel, node);
  295. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  296. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  297. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  298. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  299. return test__checkevent_breakpoint_w(evlist);
  300. }
  301. static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
  302. {
  303. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  304. struct perf_evsel, node);
  305. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  306. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  307. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  308. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  309. return test__checkevent_breakpoint_rw(evlist);
  310. }
  311. static int test__checkevent_pmu(struct perf_evlist *evlist)
  312. {
  313. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  314. struct perf_evsel, node);
  315. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  316. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  317. TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
  318. TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
  319. TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
  320. TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
  321. return 0;
  322. }
  323. static int test__checkevent_list(struct perf_evlist *evlist)
  324. {
  325. struct perf_evsel *evsel;
  326. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  327. /* r1 */
  328. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  329. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  330. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  331. TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
  332. TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
  333. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  334. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  335. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  336. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  337. /* syscalls:sys_enter_open:k */
  338. evsel = list_entry(evsel->node.next, struct perf_evsel, node);
  339. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  340. TEST_ASSERT_VAL("wrong sample_type",
  341. (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
  342. evsel->attr.sample_type);
  343. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  344. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  345. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  346. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  347. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  348. /* 1:1:hp */
  349. evsel = list_entry(evsel->node.next, struct perf_evsel, node);
  350. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  351. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  352. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  353. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  354. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  355. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  356. return 0;
  357. }
  358. static int test__checkevent_pmu_name(struct perf_evlist *evlist)
  359. {
  360. struct perf_evsel *evsel;
  361. /* cpu/config=1,name=krava/u */
  362. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  363. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  364. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  365. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  366. TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
  367. /* cpu/config=2/u" */
  368. evsel = list_entry(evsel->node.next, struct perf_evsel, node);
  369. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  370. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  371. TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
  372. TEST_ASSERT_VAL("wrong name",
  373. !strcmp(perf_evsel__name(evsel), "raw 0x2:u"));
  374. return 0;
  375. }
  376. static int test__checkterms_simple(struct list_head *terms)
  377. {
  378. struct parse_events__term *term;
  379. /* config=10 */
  380. term = list_entry(terms->next, struct parse_events__term, list);
  381. TEST_ASSERT_VAL("wrong type term",
  382. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
  383. TEST_ASSERT_VAL("wrong type val",
  384. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  385. TEST_ASSERT_VAL("wrong val", term->val.num == 10);
  386. TEST_ASSERT_VAL("wrong config", !term->config);
  387. /* config1 */
  388. term = list_entry(term->list.next, struct parse_events__term, list);
  389. TEST_ASSERT_VAL("wrong type term",
  390. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
  391. TEST_ASSERT_VAL("wrong type val",
  392. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  393. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  394. TEST_ASSERT_VAL("wrong config", !term->config);
  395. /* config2=3 */
  396. term = list_entry(term->list.next, struct parse_events__term, list);
  397. TEST_ASSERT_VAL("wrong type term",
  398. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
  399. TEST_ASSERT_VAL("wrong type val",
  400. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  401. TEST_ASSERT_VAL("wrong val", term->val.num == 3);
  402. TEST_ASSERT_VAL("wrong config", !term->config);
  403. /* umask=1*/
  404. term = list_entry(term->list.next, struct parse_events__term, list);
  405. TEST_ASSERT_VAL("wrong type term",
  406. term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
  407. TEST_ASSERT_VAL("wrong type val",
  408. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  409. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  410. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
  411. return 0;
  412. }
  413. struct test__event_st {
  414. const char *name;
  415. __u32 type;
  416. int (*check)(struct perf_evlist *evlist);
  417. };
  418. static struct test__event_st test__events[] = {
  419. [0] = {
  420. .name = "syscalls:sys_enter_open",
  421. .check = test__checkevent_tracepoint,
  422. },
  423. [1] = {
  424. .name = "syscalls:*",
  425. .check = test__checkevent_tracepoint_multi,
  426. },
  427. [2] = {
  428. .name = "r1a",
  429. .check = test__checkevent_raw,
  430. },
  431. [3] = {
  432. .name = "1:1",
  433. .check = test__checkevent_numeric,
  434. },
  435. [4] = {
  436. .name = "instructions",
  437. .check = test__checkevent_symbolic_name,
  438. },
  439. [5] = {
  440. .name = "cycles/period=100000,config2/",
  441. .check = test__checkevent_symbolic_name_config,
  442. },
  443. [6] = {
  444. .name = "faults",
  445. .check = test__checkevent_symbolic_alias,
  446. },
  447. [7] = {
  448. .name = "L1-dcache-load-miss",
  449. .check = test__checkevent_genhw,
  450. },
  451. [8] = {
  452. .name = "mem:0",
  453. .check = test__checkevent_breakpoint,
  454. },
  455. [9] = {
  456. .name = "mem:0:x",
  457. .check = test__checkevent_breakpoint_x,
  458. },
  459. [10] = {
  460. .name = "mem:0:r",
  461. .check = test__checkevent_breakpoint_r,
  462. },
  463. [11] = {
  464. .name = "mem:0:w",
  465. .check = test__checkevent_breakpoint_w,
  466. },
  467. [12] = {
  468. .name = "syscalls:sys_enter_open:k",
  469. .check = test__checkevent_tracepoint_modifier,
  470. },
  471. [13] = {
  472. .name = "syscalls:*:u",
  473. .check = test__checkevent_tracepoint_multi_modifier,
  474. },
  475. [14] = {
  476. .name = "r1a:kp",
  477. .check = test__checkevent_raw_modifier,
  478. },
  479. [15] = {
  480. .name = "1:1:hp",
  481. .check = test__checkevent_numeric_modifier,
  482. },
  483. [16] = {
  484. .name = "instructions:h",
  485. .check = test__checkevent_symbolic_name_modifier,
  486. },
  487. [17] = {
  488. .name = "faults:u",
  489. .check = test__checkevent_symbolic_alias_modifier,
  490. },
  491. [18] = {
  492. .name = "L1-dcache-load-miss:kp",
  493. .check = test__checkevent_genhw_modifier,
  494. },
  495. [19] = {
  496. .name = "mem:0:u",
  497. .check = test__checkevent_breakpoint_modifier,
  498. },
  499. [20] = {
  500. .name = "mem:0:x:k",
  501. .check = test__checkevent_breakpoint_x_modifier,
  502. },
  503. [21] = {
  504. .name = "mem:0:r:hp",
  505. .check = test__checkevent_breakpoint_r_modifier,
  506. },
  507. [22] = {
  508. .name = "mem:0:w:up",
  509. .check = test__checkevent_breakpoint_w_modifier,
  510. },
  511. [23] = {
  512. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  513. .check = test__checkevent_list,
  514. },
  515. [24] = {
  516. .name = "instructions:G",
  517. .check = test__checkevent_exclude_host_modifier,
  518. },
  519. [25] = {
  520. .name = "instructions:H",
  521. .check = test__checkevent_exclude_guest_modifier,
  522. },
  523. [26] = {
  524. .name = "mem:0:rw",
  525. .check = test__checkevent_breakpoint_rw,
  526. },
  527. [27] = {
  528. .name = "mem:0:rw:kp",
  529. .check = test__checkevent_breakpoint_rw_modifier,
  530. },
  531. };
  532. #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
  533. static struct test__event_st test__events_pmu[] = {
  534. [0] = {
  535. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  536. .check = test__checkevent_pmu,
  537. },
  538. [1] = {
  539. .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
  540. .check = test__checkevent_pmu_name,
  541. },
  542. };
  543. #define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
  544. sizeof(struct test__event_st))
  545. struct test__term {
  546. const char *str;
  547. __u32 type;
  548. int (*check)(struct list_head *terms);
  549. };
  550. static struct test__term test__terms[] = {
  551. [0] = {
  552. .str = "config=10,config1,config2=3,umask=1",
  553. .check = test__checkterms_simple,
  554. },
  555. };
  556. #define TEST__TERMS_CNT (sizeof(test__terms) / \
  557. sizeof(struct test__term))
  558. static int test_event(struct test__event_st *e)
  559. {
  560. struct perf_evlist *evlist;
  561. int ret;
  562. evlist = perf_evlist__new(NULL, NULL);
  563. if (evlist == NULL)
  564. return -ENOMEM;
  565. ret = parse_events(evlist, e->name, 0);
  566. if (ret) {
  567. pr_debug("failed to parse event '%s', err %d\n",
  568. e->name, ret);
  569. return ret;
  570. }
  571. ret = e->check(evlist);
  572. perf_evlist__delete(evlist);
  573. return ret;
  574. }
  575. static int test_events(struct test__event_st *events, unsigned cnt)
  576. {
  577. int ret = 0;
  578. unsigned i;
  579. for (i = 0; i < cnt; i++) {
  580. struct test__event_st *e = &events[i];
  581. pr_debug("running test %d '%s'\n", i, e->name);
  582. ret = test_event(e);
  583. if (ret)
  584. break;
  585. }
  586. return ret;
  587. }
  588. static int test_term(struct test__term *t)
  589. {
  590. struct list_head *terms;
  591. int ret;
  592. terms = malloc(sizeof(*terms));
  593. if (!terms)
  594. return -ENOMEM;
  595. INIT_LIST_HEAD(terms);
  596. ret = parse_events_terms(terms, t->str);
  597. if (ret) {
  598. pr_debug("failed to parse terms '%s', err %d\n",
  599. t->str , ret);
  600. return ret;
  601. }
  602. ret = t->check(terms);
  603. parse_events__free_terms(terms);
  604. return ret;
  605. }
  606. static int test_terms(struct test__term *terms, unsigned cnt)
  607. {
  608. int ret = 0;
  609. unsigned i;
  610. for (i = 0; i < cnt; i++) {
  611. struct test__term *t = &terms[i];
  612. pr_debug("running test %d '%s'\n", i, t->str);
  613. ret = test_term(t);
  614. if (ret)
  615. break;
  616. }
  617. return ret;
  618. }
  619. static int test_pmu(void)
  620. {
  621. struct stat st;
  622. char path[PATH_MAX];
  623. int ret;
  624. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  625. sysfs_find_mountpoint());
  626. ret = stat(path, &st);
  627. if (ret)
  628. pr_debug("ommiting PMU cpu tests\n");
  629. return !ret;
  630. }
  631. int parse_events__test(void)
  632. {
  633. int ret;
  634. do {
  635. ret = test_events(test__events, TEST__EVENTS_CNT);
  636. if (ret)
  637. break;
  638. if (test_pmu()) {
  639. ret = test_events(test__events_pmu,
  640. TEST__EVENTS_PMU_CNT);
  641. if (ret)
  642. break;
  643. }
  644. ret = test_terms(test__terms, TEST__TERMS_CNT);
  645. } while (0);
  646. return ret;
  647. }