parse-events-test.c 35 KB

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