parse-events.c 55 KB

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