parse-events-test.c 37 KB

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