parse-events.c 64 KB

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