parse-events.c 37 KB

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