parse-events.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  1. #include "parse-events.h"
  2. #include "evsel.h"
  3. #include "evlist.h"
  4. #include <api/fs/fs.h>
  5. #include <api/fs/debugfs.h>
  6. #include "tests.h"
  7. #include "debug.h"
  8. #include <linux/hw_breakpoint.h>
  9. #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
  10. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
  11. static int test__checkevent_tracepoint(struct perf_evlist *evlist)
  12. {
  13. struct perf_evsel *evsel = perf_evlist__first(evlist);
  14. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  15. TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
  16. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  17. TEST_ASSERT_VAL("wrong sample_type",
  18. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  19. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  20. return 0;
  21. }
  22. static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
  23. {
  24. struct perf_evsel *evsel;
  25. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  26. TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
  27. evlist__for_each(evlist, evsel) {
  28. TEST_ASSERT_VAL("wrong type",
  29. PERF_TYPE_TRACEPOINT == evsel->attr.type);
  30. TEST_ASSERT_VAL("wrong sample_type",
  31. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  32. TEST_ASSERT_VAL("wrong sample_period",
  33. 1 == evsel->attr.sample_period);
  34. }
  35. return 0;
  36. }
  37. static int test__checkevent_raw(struct perf_evlist *evlist)
  38. {
  39. struct perf_evsel *evsel = perf_evlist__first(evlist);
  40. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  41. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  42. TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
  43. return 0;
  44. }
  45. static int test__checkevent_numeric(struct perf_evlist *evlist)
  46. {
  47. struct perf_evsel *evsel = perf_evlist__first(evlist);
  48. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  49. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  50. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  51. return 0;
  52. }
  53. static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
  54. {
  55. struct perf_evsel *evsel = perf_evlist__first(evlist);
  56. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  57. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  58. TEST_ASSERT_VAL("wrong config",
  59. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  60. return 0;
  61. }
  62. static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
  63. {
  64. struct perf_evsel *evsel = perf_evlist__first(evlist);
  65. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  66. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  67. TEST_ASSERT_VAL("wrong config",
  68. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  69. TEST_ASSERT_VAL("wrong period",
  70. 100000 == evsel->attr.sample_period);
  71. TEST_ASSERT_VAL("wrong config1",
  72. 0 == evsel->attr.config1);
  73. TEST_ASSERT_VAL("wrong config2",
  74. 1 == evsel->attr.config2);
  75. return 0;
  76. }
  77. static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
  78. {
  79. struct perf_evsel *evsel = perf_evlist__first(evlist);
  80. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  81. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  82. TEST_ASSERT_VAL("wrong config",
  83. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  84. return 0;
  85. }
  86. static int test__checkevent_genhw(struct perf_evlist *evlist)
  87. {
  88. struct perf_evsel *evsel = perf_evlist__first(evlist);
  89. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  90. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
  91. TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
  92. return 0;
  93. }
  94. static int test__checkevent_breakpoint(struct perf_evlist *evlist)
  95. {
  96. struct perf_evsel *evsel = perf_evlist__first(evlist);
  97. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  98. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  99. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  100. TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
  101. evsel->attr.bp_type);
  102. TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
  103. evsel->attr.bp_len);
  104. return 0;
  105. }
  106. static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
  107. {
  108. struct perf_evsel *evsel = perf_evlist__first(evlist);
  109. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  110. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  111. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  112. TEST_ASSERT_VAL("wrong bp_type",
  113. HW_BREAKPOINT_X == evsel->attr.bp_type);
  114. TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
  115. return 0;
  116. }
  117. static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
  118. {
  119. struct perf_evsel *evsel = perf_evlist__first(evlist);
  120. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  121. TEST_ASSERT_VAL("wrong type",
  122. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  123. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  124. TEST_ASSERT_VAL("wrong bp_type",
  125. HW_BREAKPOINT_R == evsel->attr.bp_type);
  126. TEST_ASSERT_VAL("wrong bp_len",
  127. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  128. return 0;
  129. }
  130. static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
  131. {
  132. struct perf_evsel *evsel = perf_evlist__first(evlist);
  133. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  134. TEST_ASSERT_VAL("wrong type",
  135. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  136. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  137. TEST_ASSERT_VAL("wrong bp_type",
  138. HW_BREAKPOINT_W == evsel->attr.bp_type);
  139. TEST_ASSERT_VAL("wrong bp_len",
  140. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  141. return 0;
  142. }
  143. static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
  144. {
  145. struct perf_evsel *evsel = perf_evlist__first(evlist);
  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_R|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_tracepoint_modifier(struct perf_evlist *evlist)
  157. {
  158. struct perf_evsel *evsel = perf_evlist__first(evlist);
  159. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  160. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  161. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  162. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  163. return test__checkevent_tracepoint(evlist);
  164. }
  165. static int
  166. test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
  167. {
  168. struct perf_evsel *evsel;
  169. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  170. evlist__for_each(evlist, evsel) {
  171. TEST_ASSERT_VAL("wrong exclude_user",
  172. !evsel->attr.exclude_user);
  173. TEST_ASSERT_VAL("wrong exclude_kernel",
  174. evsel->attr.exclude_kernel);
  175. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  176. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  177. }
  178. return test__checkevent_tracepoint_multi(evlist);
  179. }
  180. static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
  181. {
  182. struct perf_evsel *evsel = perf_evlist__first(evlist);
  183. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  184. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  185. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  186. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  187. return test__checkevent_raw(evlist);
  188. }
  189. static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
  190. {
  191. struct perf_evsel *evsel = perf_evlist__first(evlist);
  192. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  193. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  194. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  195. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  196. return test__checkevent_numeric(evlist);
  197. }
  198. static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
  199. {
  200. struct perf_evsel *evsel = perf_evlist__first(evlist);
  201. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  202. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  203. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  204. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  205. return test__checkevent_symbolic_name(evlist);
  206. }
  207. static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
  208. {
  209. struct perf_evsel *evsel = perf_evlist__first(evlist);
  210. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  211. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  212. return test__checkevent_symbolic_name(evlist);
  213. }
  214. static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
  215. {
  216. struct perf_evsel *evsel = perf_evlist__first(evlist);
  217. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  218. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  219. return test__checkevent_symbolic_name(evlist);
  220. }
  221. static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
  222. {
  223. struct perf_evsel *evsel = perf_evlist__first(evlist);
  224. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  225. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  226. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  227. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  228. return test__checkevent_symbolic_alias(evlist);
  229. }
  230. static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
  231. {
  232. struct perf_evsel *evsel = perf_evlist__first(evlist);
  233. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  234. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  235. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  236. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  237. return test__checkevent_genhw(evlist);
  238. }
  239. static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
  240. {
  241. struct perf_evsel *evsel = perf_evlist__first(evlist);
  242. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  243. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  244. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  245. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  246. TEST_ASSERT_VAL("wrong name",
  247. !strcmp(perf_evsel__name(evsel), "mem:0:u"));
  248. return test__checkevent_breakpoint(evlist);
  249. }
  250. static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
  251. {
  252. struct perf_evsel *evsel = perf_evlist__first(evlist);
  253. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  254. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  255. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  256. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  257. TEST_ASSERT_VAL("wrong name",
  258. !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
  259. return test__checkevent_breakpoint_x(evlist);
  260. }
  261. static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
  262. {
  263. struct perf_evsel *evsel = perf_evlist__first(evlist);
  264. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  265. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  266. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  267. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  268. TEST_ASSERT_VAL("wrong name",
  269. !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
  270. return test__checkevent_breakpoint_r(evlist);
  271. }
  272. static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
  273. {
  274. struct perf_evsel *evsel = perf_evlist__first(evlist);
  275. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  276. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  277. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  278. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  279. TEST_ASSERT_VAL("wrong name",
  280. !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
  281. return test__checkevent_breakpoint_w(evlist);
  282. }
  283. static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
  284. {
  285. struct perf_evsel *evsel = perf_evlist__first(evlist);
  286. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  287. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  288. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  289. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  290. TEST_ASSERT_VAL("wrong name",
  291. !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
  292. return test__checkevent_breakpoint_rw(evlist);
  293. }
  294. static int test__checkevent_pmu(struct perf_evlist *evlist)
  295. {
  296. struct perf_evsel *evsel = perf_evlist__first(evlist);
  297. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  298. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  299. TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
  300. TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
  301. TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
  302. TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
  303. return 0;
  304. }
  305. static int test__checkevent_list(struct perf_evlist *evlist)
  306. {
  307. struct perf_evsel *evsel = perf_evlist__first(evlist);
  308. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  309. /* r1 */
  310. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  311. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  312. TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
  313. TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
  314. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  315. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  316. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  317. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  318. /* syscalls:sys_enter_open:k */
  319. evsel = perf_evsel__next(evsel);
  320. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  321. TEST_ASSERT_VAL("wrong sample_type",
  322. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  323. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  324. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  325. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  326. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  327. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  328. /* 1:1:hp */
  329. evsel = perf_evsel__next(evsel);
  330. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  331. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  332. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  333. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  334. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  335. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  336. return 0;
  337. }
  338. static int test__checkevent_pmu_name(struct perf_evlist *evlist)
  339. {
  340. struct perf_evsel *evsel = perf_evlist__first(evlist);
  341. /* cpu/config=1,name=krava/u */
  342. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  343. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  344. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  345. TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
  346. /* cpu/config=2/u" */
  347. evsel = perf_evsel__next(evsel);
  348. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  349. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  350. TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
  351. TEST_ASSERT_VAL("wrong name",
  352. !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
  353. return 0;
  354. }
  355. static int test__checkevent_pmu_events(struct perf_evlist *evlist)
  356. {
  357. struct perf_evsel *evsel = perf_evlist__first(evlist);
  358. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  359. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  360. TEST_ASSERT_VAL("wrong exclude_user",
  361. !evsel->attr.exclude_user);
  362. TEST_ASSERT_VAL("wrong exclude_kernel",
  363. evsel->attr.exclude_kernel);
  364. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  365. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  366. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  367. return 0;
  368. }
  369. static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
  370. {
  371. struct perf_evsel *evsel = perf_evlist__first(evlist);
  372. /* pmu-event:u */
  373. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  374. TEST_ASSERT_VAL("wrong exclude_user",
  375. !evsel->attr.exclude_user);
  376. TEST_ASSERT_VAL("wrong exclude_kernel",
  377. evsel->attr.exclude_kernel);
  378. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  379. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  380. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  381. /* cpu/pmu-event/u*/
  382. evsel = perf_evsel__next(evsel);
  383. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  384. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  385. TEST_ASSERT_VAL("wrong exclude_user",
  386. !evsel->attr.exclude_user);
  387. TEST_ASSERT_VAL("wrong exclude_kernel",
  388. evsel->attr.exclude_kernel);
  389. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  390. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  391. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  392. return 0;
  393. }
  394. static int test__checkterms_simple(struct list_head *terms)
  395. {
  396. struct parse_events_term *term;
  397. /* config=10 */
  398. term = list_entry(terms->next, struct parse_events_term, list);
  399. TEST_ASSERT_VAL("wrong type term",
  400. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
  401. TEST_ASSERT_VAL("wrong type val",
  402. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  403. TEST_ASSERT_VAL("wrong val", term->val.num == 10);
  404. TEST_ASSERT_VAL("wrong config", !term->config);
  405. /* config1 */
  406. term = list_entry(term->list.next, struct parse_events_term, list);
  407. TEST_ASSERT_VAL("wrong type term",
  408. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
  409. TEST_ASSERT_VAL("wrong type val",
  410. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  411. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  412. TEST_ASSERT_VAL("wrong config", !term->config);
  413. /* config2=3 */
  414. term = list_entry(term->list.next, struct parse_events_term, list);
  415. TEST_ASSERT_VAL("wrong type term",
  416. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
  417. TEST_ASSERT_VAL("wrong type val",
  418. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  419. TEST_ASSERT_VAL("wrong val", term->val.num == 3);
  420. TEST_ASSERT_VAL("wrong config", !term->config);
  421. /* umask=1*/
  422. term = list_entry(term->list.next, struct parse_events_term, list);
  423. TEST_ASSERT_VAL("wrong type term",
  424. term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
  425. TEST_ASSERT_VAL("wrong type val",
  426. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  427. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  428. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
  429. return 0;
  430. }
  431. static int test__group1(struct perf_evlist *evlist)
  432. {
  433. struct perf_evsel *evsel, *leader;
  434. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  435. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  436. /* instructions:k */
  437. evsel = leader = perf_evlist__first(evlist);
  438. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  439. TEST_ASSERT_VAL("wrong config",
  440. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  441. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  442. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  443. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  444. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  445. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  446. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  447. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  448. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  449. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  450. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  451. /* cycles:upp */
  452. evsel = perf_evsel__next(evsel);
  453. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  454. TEST_ASSERT_VAL("wrong config",
  455. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  456. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  457. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  458. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  459. /* use of precise requires exclude_guest */
  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 == 2);
  463. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  464. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  465. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  466. return 0;
  467. }
  468. static int test__group2(struct perf_evlist *evlist)
  469. {
  470. struct perf_evsel *evsel, *leader;
  471. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  472. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  473. /* faults + :ku modifier */
  474. evsel = leader = perf_evlist__first(evlist);
  475. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  476. TEST_ASSERT_VAL("wrong config",
  477. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  478. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  479. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  480. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  481. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  482. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  483. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  484. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  485. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  486. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  487. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  488. /* cache-references + :u modifier */
  489. evsel = perf_evsel__next(evsel);
  490. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  491. TEST_ASSERT_VAL("wrong config",
  492. PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
  493. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  494. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  495. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  496. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  497. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  498. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  499. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  500. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  501. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  502. /* cycles:k */
  503. evsel = perf_evsel__next(evsel);
  504. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  505. TEST_ASSERT_VAL("wrong config",
  506. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  507. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  508. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  509. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  510. 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", perf_evsel__is_group_leader(evsel));
  514. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  515. return 0;
  516. }
  517. static int test__group3(struct perf_evlist *evlist __maybe_unused)
  518. {
  519. struct perf_evsel *evsel, *leader;
  520. TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
  521. TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
  522. /* group1 syscalls:sys_enter_open:H */
  523. evsel = leader = perf_evlist__first(evlist);
  524. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  525. TEST_ASSERT_VAL("wrong sample_type",
  526. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  527. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  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", perf_evsel__is_group_leader(evsel));
  535. TEST_ASSERT_VAL("wrong group name",
  536. !strcmp(leader->group_name, "group1"));
  537. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  538. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  539. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  540. /* group1 cycles:kppp */
  541. evsel = perf_evsel__next(evsel);
  542. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  543. TEST_ASSERT_VAL("wrong config",
  544. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  545. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  546. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  547. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  548. /* use of precise requires exclude_guest */
  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 == 3);
  552. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  553. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  554. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  555. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  556. /* group2 cycles + G modifier */
  557. evsel = leader = perf_evsel__next(evsel);
  558. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  559. TEST_ASSERT_VAL("wrong config",
  560. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  561. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  562. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  563. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  564. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  565. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  566. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  567. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  568. TEST_ASSERT_VAL("wrong group name",
  569. !strcmp(leader->group_name, "group2"));
  570. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  571. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  572. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  573. /* group2 1:3 + G modifier */
  574. evsel = perf_evsel__next(evsel);
  575. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  576. TEST_ASSERT_VAL("wrong config", 3 == 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 leader", evsel->leader == leader);
  584. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  585. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  586. /* instructions:u */
  587. evsel = perf_evsel__next(evsel);
  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);
  597. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  598. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  599. return 0;
  600. }
  601. static int test__group4(struct perf_evlist *evlist __maybe_unused)
  602. {
  603. struct perf_evsel *evsel, *leader;
  604. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  605. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  606. /* cycles:u + p */
  607. evsel = leader = perf_evlist__first(evlist);
  608. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  609. TEST_ASSERT_VAL("wrong config",
  610. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  611. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  612. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  613. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  614. /* use of precise requires exclude_guest */
  615. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  616. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  617. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
  618. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  619. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  620. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  621. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  622. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  623. /* instructions:kp + p */
  624. evsel = perf_evsel__next(evsel);
  625. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  626. TEST_ASSERT_VAL("wrong config",
  627. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  628. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  629. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  630. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  631. /* use of precise requires exclude_guest */
  632. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  633. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  634. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
  635. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  636. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  637. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  638. return 0;
  639. }
  640. static int test__group5(struct perf_evlist *evlist __maybe_unused)
  641. {
  642. struct perf_evsel *evsel, *leader;
  643. TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
  644. TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
  645. /* cycles + G */
  646. evsel = leader = perf_evlist__first(evlist);
  647. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  648. TEST_ASSERT_VAL("wrong config",
  649. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  650. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  651. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  652. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  653. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  654. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  655. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  656. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  657. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  658. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  659. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  660. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  661. /* instructions + G */
  662. evsel = perf_evsel__next(evsel);
  663. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  664. TEST_ASSERT_VAL("wrong config",
  665. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  666. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  667. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  668. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  669. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  670. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  671. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  672. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  673. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  674. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  675. /* cycles:G */
  676. evsel = leader = perf_evsel__next(evsel);
  677. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  678. TEST_ASSERT_VAL("wrong config",
  679. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  680. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  681. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  682. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  683. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  684. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  685. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  686. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  687. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  688. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  689. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  690. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  691. /* instructions:G */
  692. evsel = perf_evsel__next(evsel);
  693. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  694. TEST_ASSERT_VAL("wrong config",
  695. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  696. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  697. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  698. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  699. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  700. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  701. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  702. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  703. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  704. /* cycles */
  705. evsel = perf_evsel__next(evsel);
  706. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  707. TEST_ASSERT_VAL("wrong config",
  708. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  709. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  710. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  711. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  712. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  713. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  714. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  715. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  716. return 0;
  717. }
  718. static int test__group_gh1(struct perf_evlist *evlist)
  719. {
  720. struct perf_evsel *evsel, *leader;
  721. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  722. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  723. /* cycles + :H group modifier */
  724. evsel = leader = perf_evlist__first(evlist);
  725. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  726. TEST_ASSERT_VAL("wrong config",
  727. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  728. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  729. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  730. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  731. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  732. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  733. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  734. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  735. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  736. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  737. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  738. /* cache-misses:G + :H group modifier */
  739. evsel = perf_evsel__next(evsel);
  740. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  741. TEST_ASSERT_VAL("wrong config",
  742. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  743. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  744. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  745. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  746. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  747. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  748. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  749. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  750. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  751. return 0;
  752. }
  753. static int test__group_gh2(struct perf_evlist *evlist)
  754. {
  755. struct perf_evsel *evsel, *leader;
  756. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  757. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  758. /* cycles + :G group modifier */
  759. evsel = leader = perf_evlist__first(evlist);
  760. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  761. TEST_ASSERT_VAL("wrong config",
  762. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  763. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  764. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  765. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  766. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  767. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  768. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  769. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  770. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  771. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  772. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  773. /* cache-misses:H + :G group modifier */
  774. evsel = perf_evsel__next(evsel);
  775. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  776. TEST_ASSERT_VAL("wrong config",
  777. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  778. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  779. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  780. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  781. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  782. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  783. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  784. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  785. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  786. return 0;
  787. }
  788. static int test__group_gh3(struct perf_evlist *evlist)
  789. {
  790. struct perf_evsel *evsel, *leader;
  791. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  792. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  793. /* cycles:G + :u group modifier */
  794. evsel = leader = perf_evlist__first(evlist);
  795. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  796. TEST_ASSERT_VAL("wrong config",
  797. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  798. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  799. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  800. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  801. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  802. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  803. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  804. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  805. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  806. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  807. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  808. /* cache-misses:H + :u group modifier */
  809. evsel = perf_evsel__next(evsel);
  810. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  811. TEST_ASSERT_VAL("wrong config",
  812. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  813. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  814. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  815. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  816. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  817. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  818. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  819. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  820. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  821. return 0;
  822. }
  823. static int test__group_gh4(struct perf_evlist *evlist)
  824. {
  825. struct perf_evsel *evsel, *leader;
  826. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  827. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  828. /* cycles:G + :uG group modifier */
  829. evsel = leader = perf_evlist__first(evlist);
  830. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  831. TEST_ASSERT_VAL("wrong config",
  832. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  833. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  834. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  835. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  836. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  837. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  838. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  839. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  840. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  841. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  842. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  843. /* cache-misses:H + :uG group modifier */
  844. evsel = perf_evsel__next(evsel);
  845. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  846. TEST_ASSERT_VAL("wrong config",
  847. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  848. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  849. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  850. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  851. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  852. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  853. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  854. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  855. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  856. return 0;
  857. }
  858. static int test__leader_sample1(struct perf_evlist *evlist)
  859. {
  860. struct perf_evsel *evsel, *leader;
  861. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  862. /* cycles - sampling group leader */
  863. evsel = leader = perf_evlist__first(evlist);
  864. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  865. TEST_ASSERT_VAL("wrong config",
  866. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  867. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  868. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  869. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  870. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  871. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  872. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  873. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  874. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  875. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  876. /* cache-misses - not sampling */
  877. evsel = perf_evsel__next(evsel);
  878. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  879. TEST_ASSERT_VAL("wrong config",
  880. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  881. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  882. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  883. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  884. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  885. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  886. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  887. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  888. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  889. /* branch-misses - not sampling */
  890. evsel = perf_evsel__next(evsel);
  891. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  892. TEST_ASSERT_VAL("wrong config",
  893. PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
  894. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  895. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  896. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  897. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  898. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  899. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  900. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  901. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  902. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  903. return 0;
  904. }
  905. static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
  906. {
  907. struct perf_evsel *evsel, *leader;
  908. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  909. /* instructions - sampling group leader */
  910. evsel = leader = perf_evlist__first(evlist);
  911. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  912. TEST_ASSERT_VAL("wrong config",
  913. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  914. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  915. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  916. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  917. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  918. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  919. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  920. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  921. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  922. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  923. /* branch-misses - not sampling */
  924. evsel = perf_evsel__next(evsel);
  925. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  926. TEST_ASSERT_VAL("wrong config",
  927. PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
  928. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  929. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  930. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  931. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  932. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  933. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  934. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  935. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  936. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  937. return 0;
  938. }
  939. static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
  940. {
  941. struct perf_evsel *evsel = perf_evlist__first(evlist);
  942. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  943. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  944. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  945. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  946. TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
  947. return test__checkevent_symbolic_name(evlist);
  948. }
  949. static int test__pinned_group(struct perf_evlist *evlist)
  950. {
  951. struct perf_evsel *evsel, *leader;
  952. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  953. /* cycles - group leader */
  954. evsel = leader = perf_evlist__first(evlist);
  955. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  956. TEST_ASSERT_VAL("wrong config",
  957. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  958. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  959. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  960. TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
  961. /* cache-misses - can not be pinned, but will go on with the leader */
  962. evsel = perf_evsel__next(evsel);
  963. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  964. TEST_ASSERT_VAL("wrong config",
  965. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  966. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  967. /* branch-misses - ditto */
  968. evsel = perf_evsel__next(evsel);
  969. TEST_ASSERT_VAL("wrong config",
  970. PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
  971. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  972. return 0;
  973. }
  974. static int count_tracepoints(void)
  975. {
  976. char events_path[PATH_MAX];
  977. struct dirent *events_ent;
  978. DIR *events_dir;
  979. int cnt = 0;
  980. scnprintf(events_path, PATH_MAX, "%s/tracing/events",
  981. debugfs_find_mountpoint());
  982. events_dir = opendir(events_path);
  983. TEST_ASSERT_VAL("Can't open events dir", events_dir);
  984. while ((events_ent = readdir(events_dir))) {
  985. char sys_path[PATH_MAX];
  986. struct dirent *sys_ent;
  987. DIR *sys_dir;
  988. if (!strcmp(events_ent->d_name, ".")
  989. || !strcmp(events_ent->d_name, "..")
  990. || !strcmp(events_ent->d_name, "enable")
  991. || !strcmp(events_ent->d_name, "header_event")
  992. || !strcmp(events_ent->d_name, "header_page"))
  993. continue;
  994. scnprintf(sys_path, PATH_MAX, "%s/%s",
  995. events_path, events_ent->d_name);
  996. sys_dir = opendir(sys_path);
  997. TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
  998. while ((sys_ent = readdir(sys_dir))) {
  999. if (!strcmp(sys_ent->d_name, ".")
  1000. || !strcmp(sys_ent->d_name, "..")
  1001. || !strcmp(sys_ent->d_name, "enable")
  1002. || !strcmp(sys_ent->d_name, "filter"))
  1003. continue;
  1004. cnt++;
  1005. }
  1006. closedir(sys_dir);
  1007. }
  1008. closedir(events_dir);
  1009. return cnt;
  1010. }
  1011. static int test__all_tracepoints(struct perf_evlist *evlist)
  1012. {
  1013. TEST_ASSERT_VAL("wrong events count",
  1014. count_tracepoints() == evlist->nr_entries);
  1015. return test__checkevent_tracepoint_multi(evlist);
  1016. }
  1017. struct evlist_test {
  1018. const char *name;
  1019. __u32 type;
  1020. const int id;
  1021. int (*check)(struct perf_evlist *evlist);
  1022. };
  1023. static struct evlist_test test__events[] = {
  1024. {
  1025. .name = "syscalls:sys_enter_open",
  1026. .check = test__checkevent_tracepoint,
  1027. .id = 0,
  1028. },
  1029. {
  1030. .name = "syscalls:*",
  1031. .check = test__checkevent_tracepoint_multi,
  1032. .id = 1,
  1033. },
  1034. {
  1035. .name = "r1a",
  1036. .check = test__checkevent_raw,
  1037. .id = 2,
  1038. },
  1039. {
  1040. .name = "1:1",
  1041. .check = test__checkevent_numeric,
  1042. .id = 3,
  1043. },
  1044. {
  1045. .name = "instructions",
  1046. .check = test__checkevent_symbolic_name,
  1047. .id = 4,
  1048. },
  1049. {
  1050. .name = "cycles/period=100000,config2/",
  1051. .check = test__checkevent_symbolic_name_config,
  1052. .id = 5,
  1053. },
  1054. {
  1055. .name = "faults",
  1056. .check = test__checkevent_symbolic_alias,
  1057. .id = 6,
  1058. },
  1059. {
  1060. .name = "L1-dcache-load-miss",
  1061. .check = test__checkevent_genhw,
  1062. .id = 7,
  1063. },
  1064. {
  1065. .name = "mem:0",
  1066. .check = test__checkevent_breakpoint,
  1067. .id = 8,
  1068. },
  1069. {
  1070. .name = "mem:0:x",
  1071. .check = test__checkevent_breakpoint_x,
  1072. .id = 9,
  1073. },
  1074. {
  1075. .name = "mem:0:r",
  1076. .check = test__checkevent_breakpoint_r,
  1077. .id = 10,
  1078. },
  1079. {
  1080. .name = "mem:0:w",
  1081. .check = test__checkevent_breakpoint_w,
  1082. .id = 11,
  1083. },
  1084. {
  1085. .name = "syscalls:sys_enter_open:k",
  1086. .check = test__checkevent_tracepoint_modifier,
  1087. .id = 12,
  1088. },
  1089. {
  1090. .name = "syscalls:*:u",
  1091. .check = test__checkevent_tracepoint_multi_modifier,
  1092. .id = 13,
  1093. },
  1094. {
  1095. .name = "r1a:kp",
  1096. .check = test__checkevent_raw_modifier,
  1097. .id = 14,
  1098. },
  1099. {
  1100. .name = "1:1:hp",
  1101. .check = test__checkevent_numeric_modifier,
  1102. .id = 15,
  1103. },
  1104. {
  1105. .name = "instructions:h",
  1106. .check = test__checkevent_symbolic_name_modifier,
  1107. .id = 16,
  1108. },
  1109. {
  1110. .name = "faults:u",
  1111. .check = test__checkevent_symbolic_alias_modifier,
  1112. .id = 17,
  1113. },
  1114. {
  1115. .name = "L1-dcache-load-miss:kp",
  1116. .check = test__checkevent_genhw_modifier,
  1117. .id = 18,
  1118. },
  1119. {
  1120. .name = "mem:0:u",
  1121. .check = test__checkevent_breakpoint_modifier,
  1122. .id = 19,
  1123. },
  1124. {
  1125. .name = "mem:0:x:k",
  1126. .check = test__checkevent_breakpoint_x_modifier,
  1127. .id = 20,
  1128. },
  1129. {
  1130. .name = "mem:0:r:hp",
  1131. .check = test__checkevent_breakpoint_r_modifier,
  1132. .id = 21,
  1133. },
  1134. {
  1135. .name = "mem:0:w:up",
  1136. .check = test__checkevent_breakpoint_w_modifier,
  1137. .id = 22,
  1138. },
  1139. {
  1140. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  1141. .check = test__checkevent_list,
  1142. .id = 23,
  1143. },
  1144. {
  1145. .name = "instructions:G",
  1146. .check = test__checkevent_exclude_host_modifier,
  1147. .id = 24,
  1148. },
  1149. {
  1150. .name = "instructions:H",
  1151. .check = test__checkevent_exclude_guest_modifier,
  1152. .id = 25,
  1153. },
  1154. {
  1155. .name = "mem:0:rw",
  1156. .check = test__checkevent_breakpoint_rw,
  1157. .id = 26,
  1158. },
  1159. {
  1160. .name = "mem:0:rw:kp",
  1161. .check = test__checkevent_breakpoint_rw_modifier,
  1162. .id = 27,
  1163. },
  1164. {
  1165. .name = "{instructions:k,cycles:upp}",
  1166. .check = test__group1,
  1167. .id = 28,
  1168. },
  1169. {
  1170. .name = "{faults:k,cache-references}:u,cycles:k",
  1171. .check = test__group2,
  1172. .id = 29,
  1173. },
  1174. {
  1175. .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
  1176. .check = test__group3,
  1177. .id = 30,
  1178. },
  1179. {
  1180. .name = "{cycles:u,instructions:kp}:p",
  1181. .check = test__group4,
  1182. .id = 31,
  1183. },
  1184. {
  1185. .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
  1186. .check = test__group5,
  1187. .id = 32,
  1188. },
  1189. {
  1190. .name = "*:*",
  1191. .check = test__all_tracepoints,
  1192. .id = 33,
  1193. },
  1194. {
  1195. .name = "{cycles,cache-misses:G}:H",
  1196. .check = test__group_gh1,
  1197. .id = 34,
  1198. },
  1199. {
  1200. .name = "{cycles,cache-misses:H}:G",
  1201. .check = test__group_gh2,
  1202. .id = 35,
  1203. },
  1204. {
  1205. .name = "{cycles:G,cache-misses:H}:u",
  1206. .check = test__group_gh3,
  1207. .id = 36,
  1208. },
  1209. {
  1210. .name = "{cycles:G,cache-misses:H}:uG",
  1211. .check = test__group_gh4,
  1212. .id = 37,
  1213. },
  1214. {
  1215. .name = "{cycles,cache-misses,branch-misses}:S",
  1216. .check = test__leader_sample1,
  1217. .id = 38,
  1218. },
  1219. {
  1220. .name = "{instructions,branch-misses}:Su",
  1221. .check = test__leader_sample2,
  1222. .id = 39,
  1223. },
  1224. {
  1225. .name = "instructions:uDp",
  1226. .check = test__checkevent_pinned_modifier,
  1227. .id = 40,
  1228. },
  1229. {
  1230. .name = "{cycles,cache-misses,branch-misses}:D",
  1231. .check = test__pinned_group,
  1232. .id = 41,
  1233. },
  1234. #if defined(__s390x__)
  1235. {
  1236. .name = "kvm-s390:kvm_s390_create_vm",
  1237. .check = test__checkevent_tracepoint,
  1238. .id = 100,
  1239. },
  1240. #endif
  1241. };
  1242. static struct evlist_test test__events_pmu[] = {
  1243. {
  1244. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  1245. .check = test__checkevent_pmu,
  1246. .id = 0,
  1247. },
  1248. {
  1249. .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
  1250. .check = test__checkevent_pmu_name,
  1251. .id = 1,
  1252. },
  1253. };
  1254. struct terms_test {
  1255. const char *str;
  1256. __u32 type;
  1257. int (*check)(struct list_head *terms);
  1258. };
  1259. static struct terms_test test__terms[] = {
  1260. [0] = {
  1261. .str = "config=10,config1,config2=3,umask=1",
  1262. .check = test__checkterms_simple,
  1263. },
  1264. };
  1265. static int test_event(struct evlist_test *e)
  1266. {
  1267. struct perf_evlist *evlist;
  1268. int ret;
  1269. evlist = perf_evlist__new();
  1270. if (evlist == NULL)
  1271. return -ENOMEM;
  1272. ret = parse_events(evlist, e->name);
  1273. if (ret) {
  1274. pr_debug("failed to parse event '%s', err %d\n",
  1275. e->name, ret);
  1276. } else {
  1277. ret = e->check(evlist);
  1278. }
  1279. perf_evlist__delete(evlist);
  1280. return ret;
  1281. }
  1282. static int test_events(struct evlist_test *events, unsigned cnt)
  1283. {
  1284. int ret1, ret2 = 0;
  1285. unsigned i;
  1286. for (i = 0; i < cnt; i++) {
  1287. struct evlist_test *e = &events[i];
  1288. pr_debug("running test %d '%s'\n", e->id, e->name);
  1289. ret1 = test_event(e);
  1290. if (ret1)
  1291. ret2 = ret1;
  1292. }
  1293. return ret2;
  1294. }
  1295. static int test_term(struct terms_test *t)
  1296. {
  1297. struct list_head terms;
  1298. int ret;
  1299. INIT_LIST_HEAD(&terms);
  1300. ret = parse_events_terms(&terms, t->str);
  1301. if (ret) {
  1302. pr_debug("failed to parse terms '%s', err %d\n",
  1303. t->str , ret);
  1304. return ret;
  1305. }
  1306. ret = t->check(&terms);
  1307. parse_events__free_terms(&terms);
  1308. return ret;
  1309. }
  1310. static int test_terms(struct terms_test *terms, unsigned cnt)
  1311. {
  1312. int ret = 0;
  1313. unsigned i;
  1314. for (i = 0; i < cnt; i++) {
  1315. struct terms_test *t = &terms[i];
  1316. pr_debug("running test %d '%s'\n", i, t->str);
  1317. ret = test_term(t);
  1318. if (ret)
  1319. break;
  1320. }
  1321. return ret;
  1322. }
  1323. static int test_pmu(void)
  1324. {
  1325. struct stat st;
  1326. char path[PATH_MAX];
  1327. int ret;
  1328. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  1329. sysfs__mountpoint());
  1330. ret = stat(path, &st);
  1331. if (ret)
  1332. pr_debug("omitting PMU cpu tests\n");
  1333. return !ret;
  1334. }
  1335. static int test_pmu_events(void)
  1336. {
  1337. struct stat st;
  1338. char path[PATH_MAX];
  1339. struct dirent *ent;
  1340. DIR *dir;
  1341. int ret;
  1342. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
  1343. sysfs__mountpoint());
  1344. ret = stat(path, &st);
  1345. if (ret) {
  1346. pr_debug("omitting PMU cpu events tests\n");
  1347. return 0;
  1348. }
  1349. dir = opendir(path);
  1350. if (!dir) {
  1351. pr_debug("can't open pmu event dir");
  1352. return -1;
  1353. }
  1354. while (!ret && (ent = readdir(dir))) {
  1355. #define MAX_NAME 100
  1356. struct evlist_test e;
  1357. char name[MAX_NAME];
  1358. if (!strcmp(ent->d_name, ".") ||
  1359. !strcmp(ent->d_name, ".."))
  1360. continue;
  1361. snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
  1362. e.name = name;
  1363. e.check = test__checkevent_pmu_events;
  1364. ret = test_event(&e);
  1365. if (ret)
  1366. break;
  1367. snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
  1368. e.name = name;
  1369. e.check = test__checkevent_pmu_events_mix;
  1370. ret = test_event(&e);
  1371. #undef MAX_NAME
  1372. }
  1373. closedir(dir);
  1374. return ret;
  1375. }
  1376. int test__parse_events(void)
  1377. {
  1378. int ret1, ret2 = 0;
  1379. #define TEST_EVENTS(tests) \
  1380. do { \
  1381. ret1 = test_events(tests, ARRAY_SIZE(tests)); \
  1382. if (!ret2) \
  1383. ret2 = ret1; \
  1384. } while (0)
  1385. TEST_EVENTS(test__events);
  1386. if (test_pmu())
  1387. TEST_EVENTS(test__events_pmu);
  1388. if (test_pmu()) {
  1389. int ret = test_pmu_events();
  1390. if (ret)
  1391. return ret;
  1392. }
  1393. ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
  1394. if (!ret2)
  1395. ret2 = ret1;
  1396. return ret2;
  1397. }