parse-events.c 55 KB

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