parse-events.c 71 KB

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