parse-events.c 65 KB

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