parse-events-test.c 22 KB

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