parse-events.c 38 KB

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