parse-events.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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. #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
  14. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
  15. static int test__checkevent_tracepoint(struct perf_evlist *evlist)
  16. {
  17. struct perf_evsel *evsel = perf_evlist__first(evlist);
  18. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  19. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  20. TEST_ASSERT_VAL("wrong sample_type",
  21. PERF_TP_SAMPLE_TYPE == 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_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  34. TEST_ASSERT_VAL("wrong sample_period",
  35. 1 == evsel->attr.sample_period);
  36. }
  37. return 0;
  38. }
  39. static int test__checkevent_raw(struct perf_evlist *evlist)
  40. {
  41. struct perf_evsel *evsel = perf_evlist__first(evlist);
  42. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  43. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  44. TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
  45. return 0;
  46. }
  47. static int test__checkevent_numeric(struct perf_evlist *evlist)
  48. {
  49. struct perf_evsel *evsel = perf_evlist__first(evlist);
  50. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  51. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  52. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  53. return 0;
  54. }
  55. static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
  56. {
  57. struct perf_evsel *evsel = perf_evlist__first(evlist);
  58. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  59. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  60. TEST_ASSERT_VAL("wrong config",
  61. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  62. return 0;
  63. }
  64. static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
  65. {
  66. struct perf_evsel *evsel = perf_evlist__first(evlist);
  67. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  68. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  69. TEST_ASSERT_VAL("wrong config",
  70. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  71. TEST_ASSERT_VAL("wrong period",
  72. 100000 == evsel->attr.sample_period);
  73. TEST_ASSERT_VAL("wrong config1",
  74. 0 == evsel->attr.config1);
  75. TEST_ASSERT_VAL("wrong config2",
  76. 1 == evsel->attr.config2);
  77. return 0;
  78. }
  79. static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
  80. {
  81. struct perf_evsel *evsel = perf_evlist__first(evlist);
  82. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  83. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  84. TEST_ASSERT_VAL("wrong config",
  85. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  86. return 0;
  87. }
  88. static int test__checkevent_genhw(struct perf_evlist *evlist)
  89. {
  90. struct perf_evsel *evsel = perf_evlist__first(evlist);
  91. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  92. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
  93. TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
  94. return 0;
  95. }
  96. static int test__checkevent_breakpoint(struct perf_evlist *evlist)
  97. {
  98. struct perf_evsel *evsel = perf_evlist__first(evlist);
  99. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  100. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  101. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  102. TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
  103. evsel->attr.bp_type);
  104. TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
  105. evsel->attr.bp_len);
  106. return 0;
  107. }
  108. static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
  109. {
  110. struct perf_evsel *evsel = perf_evlist__first(evlist);
  111. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  112. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  113. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  114. TEST_ASSERT_VAL("wrong bp_type",
  115. HW_BREAKPOINT_X == evsel->attr.bp_type);
  116. TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
  117. return 0;
  118. }
  119. static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
  120. {
  121. struct perf_evsel *evsel = perf_evlist__first(evlist);
  122. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  123. TEST_ASSERT_VAL("wrong type",
  124. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  125. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  126. TEST_ASSERT_VAL("wrong bp_type",
  127. HW_BREAKPOINT_R == evsel->attr.bp_type);
  128. TEST_ASSERT_VAL("wrong bp_len",
  129. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  130. return 0;
  131. }
  132. static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
  133. {
  134. struct perf_evsel *evsel = perf_evlist__first(evlist);
  135. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  136. TEST_ASSERT_VAL("wrong type",
  137. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  138. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  139. TEST_ASSERT_VAL("wrong bp_type",
  140. HW_BREAKPOINT_W == evsel->attr.bp_type);
  141. TEST_ASSERT_VAL("wrong bp_len",
  142. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  143. return 0;
  144. }
  145. static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
  146. {
  147. struct perf_evsel *evsel = perf_evlist__first(evlist);
  148. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  149. TEST_ASSERT_VAL("wrong type",
  150. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  151. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  152. TEST_ASSERT_VAL("wrong bp_type",
  153. (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
  154. TEST_ASSERT_VAL("wrong bp_len",
  155. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  156. return 0;
  157. }
  158. static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
  159. {
  160. struct perf_evsel *evsel = perf_evlist__first(evlist);
  161. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  162. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  163. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  164. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  165. return test__checkevent_tracepoint(evlist);
  166. }
  167. static int
  168. test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
  169. {
  170. struct perf_evsel *evsel;
  171. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  172. list_for_each_entry(evsel, &evlist->entries, node) {
  173. TEST_ASSERT_VAL("wrong exclude_user",
  174. !evsel->attr.exclude_user);
  175. TEST_ASSERT_VAL("wrong exclude_kernel",
  176. evsel->attr.exclude_kernel);
  177. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  178. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  179. }
  180. return test__checkevent_tracepoint_multi(evlist);
  181. }
  182. static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
  183. {
  184. struct perf_evsel *evsel = perf_evlist__first(evlist);
  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 = perf_evlist__first(evlist);
  194. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  195. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  196. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  197. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  198. return test__checkevent_numeric(evlist);
  199. }
  200. static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
  201. {
  202. struct perf_evsel *evsel = perf_evlist__first(evlist);
  203. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  204. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  205. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  206. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  207. return test__checkevent_symbolic_name(evlist);
  208. }
  209. static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
  210. {
  211. struct perf_evsel *evsel = perf_evlist__first(evlist);
  212. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  213. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  214. return test__checkevent_symbolic_name(evlist);
  215. }
  216. static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
  217. {
  218. struct perf_evsel *evsel = perf_evlist__first(evlist);
  219. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  220. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  221. return test__checkevent_symbolic_name(evlist);
  222. }
  223. static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
  224. {
  225. struct perf_evsel *evsel = perf_evlist__first(evlist);
  226. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  227. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  228. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  229. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  230. return test__checkevent_symbolic_alias(evlist);
  231. }
  232. static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
  233. {
  234. struct perf_evsel *evsel = perf_evlist__first(evlist);
  235. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  236. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  237. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  238. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  239. return test__checkevent_genhw(evlist);
  240. }
  241. static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
  242. {
  243. struct perf_evsel *evsel = perf_evlist__first(evlist);
  244. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  245. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  246. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  247. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  248. TEST_ASSERT_VAL("wrong name",
  249. !strcmp(perf_evsel__name(evsel), "mem:0:u"));
  250. return test__checkevent_breakpoint(evlist);
  251. }
  252. static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
  253. {
  254. struct perf_evsel *evsel = perf_evlist__first(evlist);
  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. TEST_ASSERT_VAL("wrong name",
  260. !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
  261. return test__checkevent_breakpoint_x(evlist);
  262. }
  263. static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
  264. {
  265. struct perf_evsel *evsel = perf_evlist__first(evlist);
  266. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  267. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  268. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  269. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  270. TEST_ASSERT_VAL("wrong name",
  271. !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
  272. return test__checkevent_breakpoint_r(evlist);
  273. }
  274. static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
  275. {
  276. struct perf_evsel *evsel = perf_evlist__first(evlist);
  277. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  278. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  279. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  280. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  281. TEST_ASSERT_VAL("wrong name",
  282. !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
  283. return test__checkevent_breakpoint_w(evlist);
  284. }
  285. static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
  286. {
  287. struct perf_evsel *evsel = perf_evlist__first(evlist);
  288. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  289. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  290. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  291. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  292. TEST_ASSERT_VAL("wrong name",
  293. !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
  294. return test__checkevent_breakpoint_rw(evlist);
  295. }
  296. static int test__checkevent_pmu(struct perf_evlist *evlist)
  297. {
  298. struct perf_evsel *evsel = perf_evlist__first(evlist);
  299. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  300. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  301. TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
  302. TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
  303. TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
  304. TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
  305. return 0;
  306. }
  307. static int test__checkevent_list(struct perf_evlist *evlist)
  308. {
  309. struct perf_evsel *evsel = perf_evlist__first(evlist);
  310. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  311. /* r1 */
  312. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  313. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  314. TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
  315. TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
  316. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  317. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  318. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  319. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  320. /* syscalls:sys_enter_open:k */
  321. evsel = perf_evsel__next(evsel);
  322. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  323. TEST_ASSERT_VAL("wrong sample_type",
  324. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  325. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  326. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  327. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  328. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  329. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  330. /* 1:1:hp */
  331. evsel = perf_evsel__next(evsel);
  332. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  333. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  334. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  335. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  336. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  337. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  338. return 0;
  339. }
  340. static int test__checkevent_pmu_name(struct perf_evlist *evlist)
  341. {
  342. struct perf_evsel *evsel = perf_evlist__first(evlist);
  343. /* cpu/config=1,name=krava/u */
  344. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  345. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  346. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  347. TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
  348. /* cpu/config=2/u" */
  349. evsel = perf_evsel__next(evsel);
  350. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  351. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  352. TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
  353. TEST_ASSERT_VAL("wrong name",
  354. !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
  355. return 0;
  356. }
  357. static int test__checkevent_pmu_events(struct perf_evlist *evlist)
  358. {
  359. struct perf_evsel *evsel;
  360. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  361. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  362. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  363. TEST_ASSERT_VAL("wrong exclude_user",
  364. !evsel->attr.exclude_user);
  365. TEST_ASSERT_VAL("wrong exclude_kernel",
  366. evsel->attr.exclude_kernel);
  367. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  368. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  369. return 0;
  370. }
  371. static int test__checkterms_simple(struct list_head *terms)
  372. {
  373. struct parse_events__term *term;
  374. /* config=10 */
  375. term = list_entry(terms->next, struct parse_events__term, list);
  376. TEST_ASSERT_VAL("wrong type term",
  377. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
  378. TEST_ASSERT_VAL("wrong type val",
  379. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  380. TEST_ASSERT_VAL("wrong val", term->val.num == 10);
  381. TEST_ASSERT_VAL("wrong config", !term->config);
  382. /* config1 */
  383. term = list_entry(term->list.next, struct parse_events__term, list);
  384. TEST_ASSERT_VAL("wrong type term",
  385. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
  386. TEST_ASSERT_VAL("wrong type val",
  387. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  388. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  389. TEST_ASSERT_VAL("wrong config", !term->config);
  390. /* config2=3 */
  391. term = list_entry(term->list.next, struct parse_events__term, list);
  392. TEST_ASSERT_VAL("wrong type term",
  393. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
  394. TEST_ASSERT_VAL("wrong type val",
  395. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  396. TEST_ASSERT_VAL("wrong val", term->val.num == 3);
  397. TEST_ASSERT_VAL("wrong config", !term->config);
  398. /* umask=1*/
  399. term = list_entry(term->list.next, struct parse_events__term, list);
  400. TEST_ASSERT_VAL("wrong type term",
  401. term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
  402. TEST_ASSERT_VAL("wrong type val",
  403. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  404. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  405. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
  406. return 0;
  407. }
  408. static int test__group1(struct perf_evlist *evlist)
  409. {
  410. struct perf_evsel *evsel, *leader;
  411. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  412. /* instructions:k */
  413. evsel = leader = perf_evlist__first(evlist);
  414. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  415. TEST_ASSERT_VAL("wrong config",
  416. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  417. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  418. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  419. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  420. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  421. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  422. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  423. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  424. /* cycles:upp */
  425. evsel = perf_evsel__next(evsel);
  426. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  427. TEST_ASSERT_VAL("wrong config",
  428. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  429. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  430. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  431. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  432. /* use of precise requires exclude_guest */
  433. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  434. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  435. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
  436. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  437. return 0;
  438. }
  439. static int test__group2(struct perf_evlist *evlist)
  440. {
  441. struct perf_evsel *evsel, *leader;
  442. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  443. /* faults + :ku modifier */
  444. evsel = leader = perf_evlist__first(evlist);
  445. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  446. TEST_ASSERT_VAL("wrong config",
  447. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  448. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  449. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  450. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  451. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  452. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  453. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  454. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  455. /* cache-references + :u modifier */
  456. evsel = perf_evsel__next(evsel);
  457. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  458. TEST_ASSERT_VAL("wrong config",
  459. PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
  460. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  461. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  462. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  463. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  464. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  465. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  466. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  467. /* cycles:k */
  468. evsel = perf_evsel__next(evsel);
  469. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  470. TEST_ASSERT_VAL("wrong config",
  471. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  472. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  473. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  474. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  475. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  476. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  477. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  478. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  479. return 0;
  480. }
  481. static int test__group3(struct perf_evlist *evlist __maybe_unused)
  482. {
  483. struct perf_evsel *evsel, *leader;
  484. TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
  485. /* group1 syscalls:sys_enter_open:H */
  486. evsel = leader = perf_evlist__first(evlist);
  487. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  488. TEST_ASSERT_VAL("wrong sample_type",
  489. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  490. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  491. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  492. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  493. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  494. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  495. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  496. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  497. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  498. TEST_ASSERT_VAL("wrong group name",
  499. !strcmp(leader->group_name, "group1"));
  500. /* group1 cycles:kppp */
  501. evsel = perf_evsel__next(evsel);
  502. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  503. TEST_ASSERT_VAL("wrong config",
  504. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  505. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  506. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  507. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  508. /* use of precise requires exclude_guest */
  509. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  510. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  511. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
  512. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  513. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  514. /* group2 cycles + G modifier */
  515. evsel = leader = perf_evsel__next(evsel);
  516. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  517. TEST_ASSERT_VAL("wrong config",
  518. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  519. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  520. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  521. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  522. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  523. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  524. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  525. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  526. TEST_ASSERT_VAL("wrong group name",
  527. !strcmp(leader->group_name, "group2"));
  528. /* group2 1:3 + G modifier */
  529. evsel = perf_evsel__next(evsel);
  530. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  531. TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
  532. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  533. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  534. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  535. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  536. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  537. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  538. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  539. /* instructions:u */
  540. evsel = perf_evsel__next(evsel);
  541. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  542. TEST_ASSERT_VAL("wrong config",
  543. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  544. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  545. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  546. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  547. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  548. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  549. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  550. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  551. return 0;
  552. }
  553. static int test__group4(struct perf_evlist *evlist __maybe_unused)
  554. {
  555. struct perf_evsel *evsel, *leader;
  556. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  557. /* cycles:u + p */
  558. evsel = leader = perf_evlist__first(evlist);
  559. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  560. TEST_ASSERT_VAL("wrong config",
  561. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  562. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  563. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  564. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  565. /* use of precise requires exclude_guest */
  566. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  567. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  568. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
  569. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  570. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  571. /* instructions:kp + p */
  572. evsel = perf_evsel__next(evsel);
  573. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  574. TEST_ASSERT_VAL("wrong config",
  575. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  576. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  577. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  578. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  579. /* use of precise requires exclude_guest */
  580. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  581. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  582. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
  583. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  584. return 0;
  585. }
  586. static int test__group5(struct perf_evlist *evlist __maybe_unused)
  587. {
  588. struct perf_evsel *evsel, *leader;
  589. TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
  590. /* cycles + G */
  591. evsel = leader = perf_evlist__first(evlist);
  592. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  593. TEST_ASSERT_VAL("wrong config",
  594. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  595. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  596. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  597. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  598. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  599. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  600. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  601. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  602. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  603. /* instructions + G */
  604. evsel = perf_evsel__next(evsel);
  605. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  606. TEST_ASSERT_VAL("wrong config",
  607. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  608. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  609. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  610. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  611. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  612. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  613. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  614. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  615. /* cycles:G */
  616. evsel = leader = perf_evsel__next(evsel);
  617. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  618. TEST_ASSERT_VAL("wrong config",
  619. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  620. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  621. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  622. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  623. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  624. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  625. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  626. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  627. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  628. /* instructions:G */
  629. evsel = perf_evsel__next(evsel);
  630. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  631. TEST_ASSERT_VAL("wrong config",
  632. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  633. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  634. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  635. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  636. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  637. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  638. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  639. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  640. /* cycles */
  641. evsel = perf_evsel__next(evsel);
  642. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  643. TEST_ASSERT_VAL("wrong config",
  644. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  645. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  646. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  647. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  648. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  649. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  650. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  651. TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
  652. return 0;
  653. }
  654. struct test__event_st {
  655. const char *name;
  656. __u32 type;
  657. int (*check)(struct perf_evlist *evlist);
  658. };
  659. static struct test__event_st test__events[] = {
  660. [0] = {
  661. .name = "syscalls:sys_enter_open",
  662. .check = test__checkevent_tracepoint,
  663. },
  664. [1] = {
  665. .name = "syscalls:*",
  666. .check = test__checkevent_tracepoint_multi,
  667. },
  668. [2] = {
  669. .name = "r1a",
  670. .check = test__checkevent_raw,
  671. },
  672. [3] = {
  673. .name = "1:1",
  674. .check = test__checkevent_numeric,
  675. },
  676. [4] = {
  677. .name = "instructions",
  678. .check = test__checkevent_symbolic_name,
  679. },
  680. [5] = {
  681. .name = "cycles/period=100000,config2/",
  682. .check = test__checkevent_symbolic_name_config,
  683. },
  684. [6] = {
  685. .name = "faults",
  686. .check = test__checkevent_symbolic_alias,
  687. },
  688. [7] = {
  689. .name = "L1-dcache-load-miss",
  690. .check = test__checkevent_genhw,
  691. },
  692. [8] = {
  693. .name = "mem:0",
  694. .check = test__checkevent_breakpoint,
  695. },
  696. [9] = {
  697. .name = "mem:0:x",
  698. .check = test__checkevent_breakpoint_x,
  699. },
  700. [10] = {
  701. .name = "mem:0:r",
  702. .check = test__checkevent_breakpoint_r,
  703. },
  704. [11] = {
  705. .name = "mem:0:w",
  706. .check = test__checkevent_breakpoint_w,
  707. },
  708. [12] = {
  709. .name = "syscalls:sys_enter_open:k",
  710. .check = test__checkevent_tracepoint_modifier,
  711. },
  712. [13] = {
  713. .name = "syscalls:*:u",
  714. .check = test__checkevent_tracepoint_multi_modifier,
  715. },
  716. [14] = {
  717. .name = "r1a:kp",
  718. .check = test__checkevent_raw_modifier,
  719. },
  720. [15] = {
  721. .name = "1:1:hp",
  722. .check = test__checkevent_numeric_modifier,
  723. },
  724. [16] = {
  725. .name = "instructions:h",
  726. .check = test__checkevent_symbolic_name_modifier,
  727. },
  728. [17] = {
  729. .name = "faults:u",
  730. .check = test__checkevent_symbolic_alias_modifier,
  731. },
  732. [18] = {
  733. .name = "L1-dcache-load-miss:kp",
  734. .check = test__checkevent_genhw_modifier,
  735. },
  736. [19] = {
  737. .name = "mem:0:u",
  738. .check = test__checkevent_breakpoint_modifier,
  739. },
  740. [20] = {
  741. .name = "mem:0:x:k",
  742. .check = test__checkevent_breakpoint_x_modifier,
  743. },
  744. [21] = {
  745. .name = "mem:0:r:hp",
  746. .check = test__checkevent_breakpoint_r_modifier,
  747. },
  748. [22] = {
  749. .name = "mem:0:w:up",
  750. .check = test__checkevent_breakpoint_w_modifier,
  751. },
  752. [23] = {
  753. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  754. .check = test__checkevent_list,
  755. },
  756. [24] = {
  757. .name = "instructions:G",
  758. .check = test__checkevent_exclude_host_modifier,
  759. },
  760. [25] = {
  761. .name = "instructions:H",
  762. .check = test__checkevent_exclude_guest_modifier,
  763. },
  764. [26] = {
  765. .name = "mem:0:rw",
  766. .check = test__checkevent_breakpoint_rw,
  767. },
  768. [27] = {
  769. .name = "mem:0:rw:kp",
  770. .check = test__checkevent_breakpoint_rw_modifier,
  771. },
  772. [28] = {
  773. .name = "{instructions:k,cycles:upp}",
  774. .check = test__group1,
  775. },
  776. [29] = {
  777. .name = "{faults:k,cache-references}:u,cycles:k",
  778. .check = test__group2,
  779. },
  780. [30] = {
  781. .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
  782. .check = test__group3,
  783. },
  784. [31] = {
  785. .name = "{cycles:u,instructions:kp}:p",
  786. .check = test__group4,
  787. },
  788. [32] = {
  789. .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
  790. .check = test__group5,
  791. },
  792. };
  793. static struct test__event_st test__events_pmu[] = {
  794. [0] = {
  795. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  796. .check = test__checkevent_pmu,
  797. },
  798. [1] = {
  799. .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
  800. .check = test__checkevent_pmu_name,
  801. },
  802. };
  803. struct test__term {
  804. const char *str;
  805. __u32 type;
  806. int (*check)(struct list_head *terms);
  807. };
  808. static struct test__term test__terms[] = {
  809. [0] = {
  810. .str = "config=10,config1,config2=3,umask=1",
  811. .check = test__checkterms_simple,
  812. },
  813. };
  814. static int test_event(struct test__event_st *e)
  815. {
  816. struct perf_evlist *evlist;
  817. int ret;
  818. evlist = perf_evlist__new(NULL, NULL);
  819. if (evlist == NULL)
  820. return -ENOMEM;
  821. ret = parse_events(evlist, e->name, 0);
  822. if (ret) {
  823. pr_debug("failed to parse event '%s', err %d\n",
  824. e->name, ret);
  825. return ret;
  826. }
  827. ret = e->check(evlist);
  828. perf_evlist__delete(evlist);
  829. return ret;
  830. }
  831. static int test_events(struct test__event_st *events, unsigned cnt)
  832. {
  833. int ret1, ret2 = 0;
  834. unsigned i;
  835. for (i = 0; i < cnt; i++) {
  836. struct test__event_st *e = &events[i];
  837. pr_debug("running test %d '%s'\n", i, e->name);
  838. ret1 = test_event(e);
  839. if (ret1)
  840. ret2 = ret1;
  841. }
  842. return ret2;
  843. }
  844. static int test_term(struct test__term *t)
  845. {
  846. struct list_head *terms;
  847. int ret;
  848. terms = malloc(sizeof(*terms));
  849. if (!terms)
  850. return -ENOMEM;
  851. INIT_LIST_HEAD(terms);
  852. ret = parse_events_terms(terms, t->str);
  853. if (ret) {
  854. pr_debug("failed to parse terms '%s', err %d\n",
  855. t->str , ret);
  856. return ret;
  857. }
  858. ret = t->check(terms);
  859. parse_events__free_terms(terms);
  860. return ret;
  861. }
  862. static int test_terms(struct test__term *terms, unsigned cnt)
  863. {
  864. int ret = 0;
  865. unsigned i;
  866. for (i = 0; i < cnt; i++) {
  867. struct test__term *t = &terms[i];
  868. pr_debug("running test %d '%s'\n", i, t->str);
  869. ret = test_term(t);
  870. if (ret)
  871. break;
  872. }
  873. return ret;
  874. }
  875. static int test_pmu(void)
  876. {
  877. struct stat st;
  878. char path[PATH_MAX];
  879. int ret;
  880. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  881. sysfs_find_mountpoint());
  882. ret = stat(path, &st);
  883. if (ret)
  884. pr_debug("omitting PMU cpu tests\n");
  885. return !ret;
  886. }
  887. static int test_pmu_events(void)
  888. {
  889. struct stat st;
  890. char path[PATH_MAX];
  891. struct dirent *ent;
  892. DIR *dir;
  893. int ret;
  894. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
  895. sysfs_find_mountpoint());
  896. ret = stat(path, &st);
  897. if (ret) {
  898. pr_debug("ommiting PMU cpu events tests\n");
  899. return 0;
  900. }
  901. dir = opendir(path);
  902. if (!dir) {
  903. pr_debug("can't open pmu event dir");
  904. return -1;
  905. }
  906. while (!ret && (ent = readdir(dir))) {
  907. #define MAX_NAME 100
  908. struct test__event_st e;
  909. char name[MAX_NAME];
  910. if (!strcmp(ent->d_name, ".") ||
  911. !strcmp(ent->d_name, ".."))
  912. continue;
  913. snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
  914. e.name = name;
  915. e.check = test__checkevent_pmu_events;
  916. ret = test_event(&e);
  917. #undef MAX_NAME
  918. }
  919. closedir(dir);
  920. return ret;
  921. }
  922. int parse_events__test(void)
  923. {
  924. int ret1, ret2 = 0;
  925. #define TEST_EVENTS(tests) \
  926. do { \
  927. ret1 = test_events(tests, ARRAY_SIZE(tests)); \
  928. if (!ret2) \
  929. ret2 = ret1; \
  930. } while (0)
  931. TEST_EVENTS(test__events);
  932. if (test_pmu())
  933. TEST_EVENTS(test__events_pmu);
  934. if (test_pmu()) {
  935. int ret = test_pmu_events();
  936. if (ret)
  937. return ret;
  938. }
  939. ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
  940. if (!ret2)
  941. ret2 = ret1;
  942. return ret2;
  943. }