parse-events-test.c 35 KB

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