parse-events.c 60 KB

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