parse-events.c 63 KB

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