parse-events.c 62 KB

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