parse-events-test.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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=krava/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(perf_evsel__name(evsel), "krava"));
  343. /* cpu/config=2/u" */
  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",
  349. !strcmp(perf_evsel__name(evsel), "raw 0x2:u"));
  350. return 0;
  351. }
  352. static int test__checkterms_simple(struct list_head *terms)
  353. {
  354. struct parse_events__term *term;
  355. /* config=10 */
  356. term = list_entry(terms->next, struct parse_events__term, list);
  357. TEST_ASSERT_VAL("wrong type term",
  358. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
  359. TEST_ASSERT_VAL("wrong type val",
  360. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  361. TEST_ASSERT_VAL("wrong val", term->val.num == 10);
  362. TEST_ASSERT_VAL("wrong config", !term->config);
  363. /* config1 */
  364. term = list_entry(term->list.next, struct parse_events__term, list);
  365. TEST_ASSERT_VAL("wrong type term",
  366. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
  367. TEST_ASSERT_VAL("wrong type val",
  368. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  369. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  370. TEST_ASSERT_VAL("wrong config", !term->config);
  371. /* config2=3 */
  372. term = list_entry(term->list.next, struct parse_events__term, list);
  373. TEST_ASSERT_VAL("wrong type term",
  374. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
  375. TEST_ASSERT_VAL("wrong type val",
  376. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  377. TEST_ASSERT_VAL("wrong val", term->val.num == 3);
  378. TEST_ASSERT_VAL("wrong config", !term->config);
  379. /* umask=1*/
  380. term = list_entry(term->list.next, struct parse_events__term, list);
  381. TEST_ASSERT_VAL("wrong type term",
  382. term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
  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 == 1);
  386. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
  387. return 0;
  388. }
  389. struct test__event_st {
  390. const char *name;
  391. __u32 type;
  392. int (*check)(struct perf_evlist *evlist);
  393. };
  394. static struct test__event_st test__events[] = {
  395. [0] = {
  396. .name = "syscalls:sys_enter_open",
  397. .check = test__checkevent_tracepoint,
  398. },
  399. [1] = {
  400. .name = "syscalls:*",
  401. .check = test__checkevent_tracepoint_multi,
  402. },
  403. [2] = {
  404. .name = "r1a",
  405. .check = test__checkevent_raw,
  406. },
  407. [3] = {
  408. .name = "1:1",
  409. .check = test__checkevent_numeric,
  410. },
  411. [4] = {
  412. .name = "instructions",
  413. .check = test__checkevent_symbolic_name,
  414. },
  415. [5] = {
  416. .name = "cycles/period=100000,config2/",
  417. .check = test__checkevent_symbolic_name_config,
  418. },
  419. [6] = {
  420. .name = "faults",
  421. .check = test__checkevent_symbolic_alias,
  422. },
  423. [7] = {
  424. .name = "L1-dcache-load-miss",
  425. .check = test__checkevent_genhw,
  426. },
  427. [8] = {
  428. .name = "mem:0",
  429. .check = test__checkevent_breakpoint,
  430. },
  431. [9] = {
  432. .name = "mem:0:x",
  433. .check = test__checkevent_breakpoint_x,
  434. },
  435. [10] = {
  436. .name = "mem:0:r",
  437. .check = test__checkevent_breakpoint_r,
  438. },
  439. [11] = {
  440. .name = "mem:0:w",
  441. .check = test__checkevent_breakpoint_w,
  442. },
  443. [12] = {
  444. .name = "syscalls:sys_enter_open:k",
  445. .check = test__checkevent_tracepoint_modifier,
  446. },
  447. [13] = {
  448. .name = "syscalls:*:u",
  449. .check = test__checkevent_tracepoint_multi_modifier,
  450. },
  451. [14] = {
  452. .name = "r1a:kp",
  453. .check = test__checkevent_raw_modifier,
  454. },
  455. [15] = {
  456. .name = "1:1:hp",
  457. .check = test__checkevent_numeric_modifier,
  458. },
  459. [16] = {
  460. .name = "instructions:h",
  461. .check = test__checkevent_symbolic_name_modifier,
  462. },
  463. [17] = {
  464. .name = "faults:u",
  465. .check = test__checkevent_symbolic_alias_modifier,
  466. },
  467. [18] = {
  468. .name = "L1-dcache-load-miss:kp",
  469. .check = test__checkevent_genhw_modifier,
  470. },
  471. [19] = {
  472. .name = "mem:0:u",
  473. .check = test__checkevent_breakpoint_modifier,
  474. },
  475. [20] = {
  476. .name = "mem:0:x:k",
  477. .check = test__checkevent_breakpoint_x_modifier,
  478. },
  479. [21] = {
  480. .name = "mem:0:r:hp",
  481. .check = test__checkevent_breakpoint_r_modifier,
  482. },
  483. [22] = {
  484. .name = "mem:0:w:up",
  485. .check = test__checkevent_breakpoint_w_modifier,
  486. },
  487. [23] = {
  488. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  489. .check = test__checkevent_list,
  490. },
  491. [24] = {
  492. .name = "instructions:G",
  493. .check = test__checkevent_exclude_host_modifier,
  494. },
  495. [25] = {
  496. .name = "instructions:H",
  497. .check = test__checkevent_exclude_guest_modifier,
  498. },
  499. };
  500. #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
  501. static struct test__event_st test__events_pmu[] = {
  502. [0] = {
  503. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  504. .check = test__checkevent_pmu,
  505. },
  506. [1] = {
  507. .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
  508. .check = test__checkevent_pmu_name,
  509. },
  510. };
  511. #define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
  512. sizeof(struct test__event_st))
  513. struct test__term {
  514. const char *str;
  515. __u32 type;
  516. int (*check)(struct list_head *terms);
  517. };
  518. static struct test__term test__terms[] = {
  519. [0] = {
  520. .str = "config=10,config1,config2=3,umask=1",
  521. .check = test__checkterms_simple,
  522. },
  523. };
  524. #define TEST__TERMS_CNT (sizeof(test__terms) / \
  525. sizeof(struct test__term))
  526. static int test_event(struct test__event_st *e)
  527. {
  528. struct perf_evlist *evlist;
  529. int ret;
  530. evlist = perf_evlist__new(NULL, NULL);
  531. if (evlist == NULL)
  532. return -ENOMEM;
  533. ret = parse_events(evlist, e->name, 0);
  534. if (ret) {
  535. pr_debug("failed to parse event '%s', err %d\n",
  536. e->name, ret);
  537. return ret;
  538. }
  539. ret = e->check(evlist);
  540. perf_evlist__delete(evlist);
  541. return ret;
  542. }
  543. static int test_events(struct test__event_st *events, unsigned cnt)
  544. {
  545. int ret = 0;
  546. unsigned i;
  547. for (i = 0; i < cnt; i++) {
  548. struct test__event_st *e = &events[i];
  549. pr_debug("running test %d '%s'\n", i, e->name);
  550. ret = test_event(e);
  551. if (ret)
  552. break;
  553. }
  554. return ret;
  555. }
  556. static int test_term(struct test__term *t)
  557. {
  558. struct list_head *terms;
  559. int ret;
  560. terms = malloc(sizeof(*terms));
  561. if (!terms)
  562. return -ENOMEM;
  563. INIT_LIST_HEAD(terms);
  564. ret = parse_events_terms(terms, t->str);
  565. if (ret) {
  566. pr_debug("failed to parse terms '%s', err %d\n",
  567. t->str , ret);
  568. return ret;
  569. }
  570. ret = t->check(terms);
  571. parse_events__free_terms(terms);
  572. return ret;
  573. }
  574. static int test_terms(struct test__term *terms, unsigned cnt)
  575. {
  576. int ret = 0;
  577. unsigned i;
  578. for (i = 0; i < cnt; i++) {
  579. struct test__term *t = &terms[i];
  580. pr_debug("running test %d '%s'\n", i, t->str);
  581. ret = test_term(t);
  582. if (ret)
  583. break;
  584. }
  585. return ret;
  586. }
  587. static int test_pmu(void)
  588. {
  589. struct stat st;
  590. char path[PATH_MAX];
  591. int ret;
  592. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  593. sysfs_find_mountpoint());
  594. ret = stat(path, &st);
  595. if (ret)
  596. pr_debug("ommiting PMU cpu tests\n");
  597. return !ret;
  598. }
  599. int parse_events__test(void)
  600. {
  601. int ret;
  602. do {
  603. ret = test_events(test__events, TEST__EVENTS_CNT);
  604. if (ret)
  605. break;
  606. if (test_pmu()) {
  607. ret = test_events(test__events_pmu,
  608. TEST__EVENTS_PMU_CNT);
  609. if (ret)
  610. break;
  611. }
  612. ret = test_terms(test__terms, TEST__TERMS_CNT);
  613. } while (0);
  614. return ret;
  615. }