parse-events.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. #include "parse-events.h"
  2. #include "evsel.h"
  3. #include "evlist.h"
  4. #include "sysfs.h"
  5. #include <lk/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. list_for_each_entry(evsel, &evlist->entries, node) {
  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. list_for_each_entry(evsel, &evlist->entries, node) {
  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;
  357. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  358. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  359. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  360. TEST_ASSERT_VAL("wrong exclude_user",
  361. !evsel->attr.exclude_user);
  362. TEST_ASSERT_VAL("wrong exclude_kernel",
  363. evsel->attr.exclude_kernel);
  364. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  365. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  366. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  367. return 0;
  368. }
  369. static int test__checkterms_simple(struct list_head *terms)
  370. {
  371. struct parse_events_term *term;
  372. /* config=10 */
  373. term = list_entry(terms->next, struct parse_events_term, list);
  374. TEST_ASSERT_VAL("wrong type term",
  375. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
  376. TEST_ASSERT_VAL("wrong type val",
  377. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  378. TEST_ASSERT_VAL("wrong val", term->val.num == 10);
  379. TEST_ASSERT_VAL("wrong config", !term->config);
  380. /* config1 */
  381. term = list_entry(term->list.next, struct parse_events_term, list);
  382. TEST_ASSERT_VAL("wrong type term",
  383. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
  384. TEST_ASSERT_VAL("wrong type val",
  385. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  386. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  387. TEST_ASSERT_VAL("wrong config", !term->config);
  388. /* config2=3 */
  389. term = list_entry(term->list.next, struct parse_events_term, list);
  390. TEST_ASSERT_VAL("wrong type term",
  391. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
  392. TEST_ASSERT_VAL("wrong type val",
  393. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  394. TEST_ASSERT_VAL("wrong val", term->val.num == 3);
  395. TEST_ASSERT_VAL("wrong config", !term->config);
  396. /* umask=1*/
  397. term = list_entry(term->list.next, struct parse_events_term, list);
  398. TEST_ASSERT_VAL("wrong type term",
  399. term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
  400. TEST_ASSERT_VAL("wrong type val",
  401. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  402. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  403. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
  404. return 0;
  405. }
  406. static int test__group1(struct perf_evlist *evlist)
  407. {
  408. struct perf_evsel *evsel, *leader;
  409. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  410. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  411. /* instructions:k */
  412. evsel = leader = perf_evlist__first(evlist);
  413. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  414. TEST_ASSERT_VAL("wrong config",
  415. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  416. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  417. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  418. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  419. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  420. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  421. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  422. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  423. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  424. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  425. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  426. /* cycles:upp */
  427. evsel = perf_evsel__next(evsel);
  428. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  429. TEST_ASSERT_VAL("wrong config",
  430. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  431. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  432. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  433. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  434. /* use of precise requires exclude_guest */
  435. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  436. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  437. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
  438. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  439. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  440. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  441. return 0;
  442. }
  443. static int test__group2(struct perf_evlist *evlist)
  444. {
  445. struct perf_evsel *evsel, *leader;
  446. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  447. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  448. /* faults + :ku modifier */
  449. evsel = leader = perf_evlist__first(evlist);
  450. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  451. TEST_ASSERT_VAL("wrong config",
  452. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  453. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  454. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  455. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  456. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  457. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  458. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  459. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  460. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  461. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  462. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  463. /* cache-references + :u modifier */
  464. evsel = perf_evsel__next(evsel);
  465. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  466. TEST_ASSERT_VAL("wrong config",
  467. PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
  468. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  469. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  470. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  471. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  472. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  473. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  474. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  475. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  476. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  477. /* cycles:k */
  478. evsel = perf_evsel__next(evsel);
  479. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  480. TEST_ASSERT_VAL("wrong config",
  481. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  482. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  483. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  484. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  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);
  488. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  489. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  490. return 0;
  491. }
  492. static int test__group3(struct perf_evlist *evlist __maybe_unused)
  493. {
  494. struct perf_evsel *evsel, *leader;
  495. TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
  496. TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
  497. /* group1 syscalls:sys_enter_open:H */
  498. evsel = leader = perf_evlist__first(evlist);
  499. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  500. TEST_ASSERT_VAL("wrong sample_type",
  501. PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
  502. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  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 group name",
  511. !strcmp(leader->group_name, "group1"));
  512. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  513. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  514. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  515. /* group1 cycles:kppp */
  516. evsel = perf_evsel__next(evsel);
  517. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  518. TEST_ASSERT_VAL("wrong config",
  519. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  520. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  521. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  522. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  523. /* use of precise requires exclude_guest */
  524. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  525. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  526. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
  527. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  528. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  529. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  530. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  531. /* group2 cycles + G modifier */
  532. evsel = leader = perf_evsel__next(evsel);
  533. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  534. TEST_ASSERT_VAL("wrong config",
  535. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  536. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  537. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  538. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  539. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  540. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  541. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  542. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  543. TEST_ASSERT_VAL("wrong group name",
  544. !strcmp(leader->group_name, "group2"));
  545. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  546. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  547. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  548. /* group2 1:3 + G modifier */
  549. evsel = perf_evsel__next(evsel);
  550. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  551. TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
  552. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  553. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  554. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  555. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  556. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  557. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  558. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  559. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  560. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  561. /* instructions:u */
  562. evsel = perf_evsel__next(evsel);
  563. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  564. TEST_ASSERT_VAL("wrong config",
  565. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  566. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  567. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  568. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  569. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  570. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  571. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  572. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  573. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  574. return 0;
  575. }
  576. static int test__group4(struct perf_evlist *evlist __maybe_unused)
  577. {
  578. struct perf_evsel *evsel, *leader;
  579. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  580. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  581. /* cycles:u + p */
  582. evsel = leader = perf_evlist__first(evlist);
  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. /* use of precise requires exclude_guest */
  590. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  591. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  592. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
  593. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  594. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  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. /* instructions:kp + p */
  599. evsel = perf_evsel__next(evsel);
  600. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  601. TEST_ASSERT_VAL("wrong config",
  602. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  603. TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
  604. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  605. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  606. /* use of precise requires exclude_guest */
  607. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  608. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  609. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
  610. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  611. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  612. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  613. return 0;
  614. }
  615. static int test__group5(struct perf_evlist *evlist __maybe_unused)
  616. {
  617. struct perf_evsel *evsel, *leader;
  618. TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
  619. TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
  620. /* cycles + G */
  621. evsel = leader = perf_evlist__first(evlist);
  622. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  623. TEST_ASSERT_VAL("wrong config",
  624. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  625. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  626. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  627. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  628. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  629. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  630. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  631. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  632. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  633. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  634. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  635. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  636. /* instructions + G */
  637. evsel = perf_evsel__next(evsel);
  638. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  639. TEST_ASSERT_VAL("wrong config",
  640. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  641. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  642. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  643. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  644. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  645. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  646. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  647. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  648. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  649. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  650. /* cycles:G */
  651. evsel = leader = perf_evsel__next(evsel);
  652. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  653. TEST_ASSERT_VAL("wrong config",
  654. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  655. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  656. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  657. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  658. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  659. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  660. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  661. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  662. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  663. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  664. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  665. TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
  666. /* instructions:G */
  667. evsel = perf_evsel__next(evsel);
  668. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  669. TEST_ASSERT_VAL("wrong config",
  670. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  671. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  672. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  673. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  674. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  675. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  676. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  677. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  678. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  679. /* cycles */
  680. evsel = perf_evsel__next(evsel);
  681. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  682. TEST_ASSERT_VAL("wrong config",
  683. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  684. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  685. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  686. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  687. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  688. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  689. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  690. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  691. return 0;
  692. }
  693. static int test__group_gh1(struct perf_evlist *evlist)
  694. {
  695. struct perf_evsel *evsel, *leader;
  696. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  697. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  698. /* cycles + :H group modifier */
  699. evsel = leader = perf_evlist__first(evlist);
  700. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  701. TEST_ASSERT_VAL("wrong config",
  702. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  703. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  704. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  705. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  706. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  707. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  708. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  709. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  710. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  711. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  712. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  713. /* cache-misses:G + :H group modifier */
  714. evsel = perf_evsel__next(evsel);
  715. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  716. TEST_ASSERT_VAL("wrong config",
  717. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  718. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  719. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  720. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  721. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  722. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  723. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  724. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  725. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  726. return 0;
  727. }
  728. static int test__group_gh2(struct perf_evlist *evlist)
  729. {
  730. struct perf_evsel *evsel, *leader;
  731. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  732. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  733. /* cycles + :G group modifier */
  734. evsel = leader = perf_evlist__first(evlist);
  735. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  736. TEST_ASSERT_VAL("wrong config",
  737. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  738. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  739. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  740. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  741. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  742. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  743. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  744. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  745. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  746. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  747. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  748. /* cache-misses:H + :G group modifier */
  749. evsel = perf_evsel__next(evsel);
  750. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  751. TEST_ASSERT_VAL("wrong config",
  752. PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
  760. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  761. return 0;
  762. }
  763. static int test__group_gh3(struct perf_evlist *evlist)
  764. {
  765. struct perf_evsel *evsel, *leader;
  766. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  767. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  768. /* cycles:G + :u group modifier */
  769. evsel = leader = perf_evlist__first(evlist);
  770. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  771. TEST_ASSERT_VAL("wrong config",
  772. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  773. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  774. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  775. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  776. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  777. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  778. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  779. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  780. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  781. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  782. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  783. /* cache-misses:H + :u group modifier */
  784. evsel = perf_evsel__next(evsel);
  785. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  786. TEST_ASSERT_VAL("wrong config",
  787. PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
  795. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  796. return 0;
  797. }
  798. static int test__group_gh4(struct perf_evlist *evlist)
  799. {
  800. struct perf_evsel *evsel, *leader;
  801. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  802. TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
  803. /* cycles:G + :uG group modifier */
  804. evsel = leader = perf_evlist__first(evlist);
  805. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  806. TEST_ASSERT_VAL("wrong config",
  807. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  808. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  809. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  810. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  811. TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
  812. TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
  813. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  814. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  815. TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
  816. TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
  817. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
  818. /* cache-misses:H + :uG group modifier */
  819. evsel = perf_evsel__next(evsel);
  820. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  821. TEST_ASSERT_VAL("wrong config",
  822. PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
  830. TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
  831. return 0;
  832. }
  833. static int test__leader_sample1(struct perf_evlist *evlist)
  834. {
  835. struct perf_evsel *evsel, *leader;
  836. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  837. /* cycles - sampling group leader */
  838. evsel = leader = perf_evlist__first(evlist);
  839. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  840. TEST_ASSERT_VAL("wrong config",
  841. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  842. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  843. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  844. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  845. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  846. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  847. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  848. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  849. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  850. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  851. /* cache-misses - not sampling */
  852. evsel = perf_evsel__next(evsel);
  853. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  854. TEST_ASSERT_VAL("wrong config",
  855. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  856. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  857. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  858. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  859. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  860. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  861. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  862. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  863. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  864. /* branch-misses - not sampling */
  865. evsel = perf_evsel__next(evsel);
  866. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  867. TEST_ASSERT_VAL("wrong config",
  868. PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
  869. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  870. TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
  871. TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
  872. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  873. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  874. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  875. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  876. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  877. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  878. return 0;
  879. }
  880. static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
  881. {
  882. struct perf_evsel *evsel, *leader;
  883. TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
  884. /* instructions - sampling group leader */
  885. evsel = leader = perf_evlist__first(evlist);
  886. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  887. TEST_ASSERT_VAL("wrong config",
  888. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  889. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  890. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  891. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  892. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  893. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  894. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  895. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  896. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  897. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  898. /* branch-misses - not sampling */
  899. evsel = perf_evsel__next(evsel);
  900. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  901. TEST_ASSERT_VAL("wrong config",
  902. PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
  903. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  904. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  905. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  906. TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
  907. TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
  908. TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
  909. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  910. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  911. TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
  912. return 0;
  913. }
  914. static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
  915. {
  916. struct perf_evsel *evsel = perf_evlist__first(evlist);
  917. TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
  918. TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
  919. TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
  920. TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
  921. TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
  922. return test__checkevent_symbolic_name(evlist);
  923. }
  924. static int test__pinned_group(struct perf_evlist *evlist)
  925. {
  926. struct perf_evsel *evsel, *leader;
  927. TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
  928. /* cycles - group leader */
  929. evsel = leader = perf_evlist__first(evlist);
  930. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  931. TEST_ASSERT_VAL("wrong config",
  932. PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
  933. TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
  934. TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
  935. TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
  936. /* cache-misses - can not be pinned, but will go on with the leader */
  937. evsel = perf_evsel__next(evsel);
  938. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  939. TEST_ASSERT_VAL("wrong config",
  940. PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
  941. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  942. /* branch-misses - ditto */
  943. evsel = perf_evsel__next(evsel);
  944. TEST_ASSERT_VAL("wrong config",
  945. PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
  946. TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
  947. return 0;
  948. }
  949. static int count_tracepoints(void)
  950. {
  951. char events_path[PATH_MAX];
  952. struct dirent *events_ent;
  953. DIR *events_dir;
  954. int cnt = 0;
  955. scnprintf(events_path, PATH_MAX, "%s/tracing/events",
  956. debugfs_find_mountpoint());
  957. events_dir = opendir(events_path);
  958. TEST_ASSERT_VAL("Can't open events dir", events_dir);
  959. while ((events_ent = readdir(events_dir))) {
  960. char sys_path[PATH_MAX];
  961. struct dirent *sys_ent;
  962. DIR *sys_dir;
  963. if (!strcmp(events_ent->d_name, ".")
  964. || !strcmp(events_ent->d_name, "..")
  965. || !strcmp(events_ent->d_name, "enable")
  966. || !strcmp(events_ent->d_name, "header_event")
  967. || !strcmp(events_ent->d_name, "header_page"))
  968. continue;
  969. scnprintf(sys_path, PATH_MAX, "%s/%s",
  970. events_path, events_ent->d_name);
  971. sys_dir = opendir(sys_path);
  972. TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
  973. while ((sys_ent = readdir(sys_dir))) {
  974. if (!strcmp(sys_ent->d_name, ".")
  975. || !strcmp(sys_ent->d_name, "..")
  976. || !strcmp(sys_ent->d_name, "enable")
  977. || !strcmp(sys_ent->d_name, "filter"))
  978. continue;
  979. cnt++;
  980. }
  981. closedir(sys_dir);
  982. }
  983. closedir(events_dir);
  984. return cnt;
  985. }
  986. static int test__all_tracepoints(struct perf_evlist *evlist)
  987. {
  988. TEST_ASSERT_VAL("wrong events count",
  989. count_tracepoints() == evlist->nr_entries);
  990. return test__checkevent_tracepoint_multi(evlist);
  991. }
  992. struct evlist_test {
  993. const char *name;
  994. __u32 type;
  995. int (*check)(struct perf_evlist *evlist);
  996. };
  997. static struct evlist_test test__events[] = {
  998. [0] = {
  999. .name = "syscalls:sys_enter_open",
  1000. .check = test__checkevent_tracepoint,
  1001. },
  1002. [1] = {
  1003. .name = "syscalls:*",
  1004. .check = test__checkevent_tracepoint_multi,
  1005. },
  1006. [2] = {
  1007. .name = "r1a",
  1008. .check = test__checkevent_raw,
  1009. },
  1010. [3] = {
  1011. .name = "1:1",
  1012. .check = test__checkevent_numeric,
  1013. },
  1014. [4] = {
  1015. .name = "instructions",
  1016. .check = test__checkevent_symbolic_name,
  1017. },
  1018. [5] = {
  1019. .name = "cycles/period=100000,config2/",
  1020. .check = test__checkevent_symbolic_name_config,
  1021. },
  1022. [6] = {
  1023. .name = "faults",
  1024. .check = test__checkevent_symbolic_alias,
  1025. },
  1026. [7] = {
  1027. .name = "L1-dcache-load-miss",
  1028. .check = test__checkevent_genhw,
  1029. },
  1030. [8] = {
  1031. .name = "mem:0",
  1032. .check = test__checkevent_breakpoint,
  1033. },
  1034. [9] = {
  1035. .name = "mem:0:x",
  1036. .check = test__checkevent_breakpoint_x,
  1037. },
  1038. [10] = {
  1039. .name = "mem:0:r",
  1040. .check = test__checkevent_breakpoint_r,
  1041. },
  1042. [11] = {
  1043. .name = "mem:0:w",
  1044. .check = test__checkevent_breakpoint_w,
  1045. },
  1046. [12] = {
  1047. .name = "syscalls:sys_enter_open:k",
  1048. .check = test__checkevent_tracepoint_modifier,
  1049. },
  1050. [13] = {
  1051. .name = "syscalls:*:u",
  1052. .check = test__checkevent_tracepoint_multi_modifier,
  1053. },
  1054. [14] = {
  1055. .name = "r1a:kp",
  1056. .check = test__checkevent_raw_modifier,
  1057. },
  1058. [15] = {
  1059. .name = "1:1:hp",
  1060. .check = test__checkevent_numeric_modifier,
  1061. },
  1062. [16] = {
  1063. .name = "instructions:h",
  1064. .check = test__checkevent_symbolic_name_modifier,
  1065. },
  1066. [17] = {
  1067. .name = "faults:u",
  1068. .check = test__checkevent_symbolic_alias_modifier,
  1069. },
  1070. [18] = {
  1071. .name = "L1-dcache-load-miss:kp",
  1072. .check = test__checkevent_genhw_modifier,
  1073. },
  1074. [19] = {
  1075. .name = "mem:0:u",
  1076. .check = test__checkevent_breakpoint_modifier,
  1077. },
  1078. [20] = {
  1079. .name = "mem:0:x:k",
  1080. .check = test__checkevent_breakpoint_x_modifier,
  1081. },
  1082. [21] = {
  1083. .name = "mem:0:r:hp",
  1084. .check = test__checkevent_breakpoint_r_modifier,
  1085. },
  1086. [22] = {
  1087. .name = "mem:0:w:up",
  1088. .check = test__checkevent_breakpoint_w_modifier,
  1089. },
  1090. [23] = {
  1091. .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
  1092. .check = test__checkevent_list,
  1093. },
  1094. [24] = {
  1095. .name = "instructions:G",
  1096. .check = test__checkevent_exclude_host_modifier,
  1097. },
  1098. [25] = {
  1099. .name = "instructions:H",
  1100. .check = test__checkevent_exclude_guest_modifier,
  1101. },
  1102. [26] = {
  1103. .name = "mem:0:rw",
  1104. .check = test__checkevent_breakpoint_rw,
  1105. },
  1106. [27] = {
  1107. .name = "mem:0:rw:kp",
  1108. .check = test__checkevent_breakpoint_rw_modifier,
  1109. },
  1110. [28] = {
  1111. .name = "{instructions:k,cycles:upp}",
  1112. .check = test__group1,
  1113. },
  1114. [29] = {
  1115. .name = "{faults:k,cache-references}:u,cycles:k",
  1116. .check = test__group2,
  1117. },
  1118. [30] = {
  1119. .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
  1120. .check = test__group3,
  1121. },
  1122. [31] = {
  1123. .name = "{cycles:u,instructions:kp}:p",
  1124. .check = test__group4,
  1125. },
  1126. [32] = {
  1127. .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
  1128. .check = test__group5,
  1129. },
  1130. [33] = {
  1131. .name = "*:*",
  1132. .check = test__all_tracepoints,
  1133. },
  1134. [34] = {
  1135. .name = "{cycles,cache-misses:G}:H",
  1136. .check = test__group_gh1,
  1137. },
  1138. [35] = {
  1139. .name = "{cycles,cache-misses:H}:G",
  1140. .check = test__group_gh2,
  1141. },
  1142. [36] = {
  1143. .name = "{cycles:G,cache-misses:H}:u",
  1144. .check = test__group_gh3,
  1145. },
  1146. [37] = {
  1147. .name = "{cycles:G,cache-misses:H}:uG",
  1148. .check = test__group_gh4,
  1149. },
  1150. [38] = {
  1151. .name = "{cycles,cache-misses,branch-misses}:S",
  1152. .check = test__leader_sample1,
  1153. },
  1154. [39] = {
  1155. .name = "{instructions,branch-misses}:Su",
  1156. .check = test__leader_sample2,
  1157. },
  1158. [40] = {
  1159. .name = "instructions:uDp",
  1160. .check = test__checkevent_pinned_modifier,
  1161. },
  1162. [41] = {
  1163. .name = "{cycles,cache-misses,branch-misses}:D",
  1164. .check = test__pinned_group,
  1165. },
  1166. };
  1167. static struct evlist_test test__events_pmu[] = {
  1168. [0] = {
  1169. .name = "cpu/config=10,config1,config2=3,period=1000/u",
  1170. .check = test__checkevent_pmu,
  1171. },
  1172. [1] = {
  1173. .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
  1174. .check = test__checkevent_pmu_name,
  1175. },
  1176. };
  1177. struct terms_test {
  1178. const char *str;
  1179. __u32 type;
  1180. int (*check)(struct list_head *terms);
  1181. };
  1182. static struct terms_test test__terms[] = {
  1183. [0] = {
  1184. .str = "config=10,config1,config2=3,umask=1",
  1185. .check = test__checkterms_simple,
  1186. },
  1187. };
  1188. static int test_event(struct evlist_test *e)
  1189. {
  1190. struct perf_evlist *evlist;
  1191. int ret;
  1192. evlist = perf_evlist__new();
  1193. if (evlist == NULL)
  1194. return -ENOMEM;
  1195. ret = parse_events(evlist, e->name);
  1196. if (ret) {
  1197. pr_debug("failed to parse event '%s', err %d\n",
  1198. e->name, ret);
  1199. return ret;
  1200. }
  1201. ret = e->check(evlist);
  1202. perf_evlist__delete(evlist);
  1203. return ret;
  1204. }
  1205. static int test_events(struct evlist_test *events, unsigned cnt)
  1206. {
  1207. int ret1, ret2 = 0;
  1208. unsigned i;
  1209. for (i = 0; i < cnt; i++) {
  1210. struct evlist_test *e = &events[i];
  1211. pr_debug("running test %d '%s'\n", i, e->name);
  1212. ret1 = test_event(e);
  1213. if (ret1)
  1214. ret2 = ret1;
  1215. }
  1216. return ret2;
  1217. }
  1218. static int test_term(struct terms_test *t)
  1219. {
  1220. struct list_head terms;
  1221. int ret;
  1222. INIT_LIST_HEAD(&terms);
  1223. ret = parse_events_terms(&terms, t->str);
  1224. if (ret) {
  1225. pr_debug("failed to parse terms '%s', err %d\n",
  1226. t->str , ret);
  1227. return ret;
  1228. }
  1229. ret = t->check(&terms);
  1230. parse_events__free_terms(&terms);
  1231. return ret;
  1232. }
  1233. static int test_terms(struct terms_test *terms, unsigned cnt)
  1234. {
  1235. int ret = 0;
  1236. unsigned i;
  1237. for (i = 0; i < cnt; i++) {
  1238. struct terms_test *t = &terms[i];
  1239. pr_debug("running test %d '%s'\n", i, t->str);
  1240. ret = test_term(t);
  1241. if (ret)
  1242. break;
  1243. }
  1244. return ret;
  1245. }
  1246. static int test_pmu(void)
  1247. {
  1248. struct stat st;
  1249. char path[PATH_MAX];
  1250. int ret;
  1251. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
  1252. sysfs_find_mountpoint());
  1253. ret = stat(path, &st);
  1254. if (ret)
  1255. pr_debug("omitting PMU cpu tests\n");
  1256. return !ret;
  1257. }
  1258. static int test_pmu_events(void)
  1259. {
  1260. struct stat st;
  1261. char path[PATH_MAX];
  1262. struct dirent *ent;
  1263. DIR *dir;
  1264. int ret;
  1265. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
  1266. sysfs_find_mountpoint());
  1267. ret = stat(path, &st);
  1268. if (ret) {
  1269. pr_debug("omitting PMU cpu events tests\n");
  1270. return 0;
  1271. }
  1272. dir = opendir(path);
  1273. if (!dir) {
  1274. pr_debug("can't open pmu event dir");
  1275. return -1;
  1276. }
  1277. while (!ret && (ent = readdir(dir))) {
  1278. #define MAX_NAME 100
  1279. struct evlist_test e;
  1280. char name[MAX_NAME];
  1281. if (!strcmp(ent->d_name, ".") ||
  1282. !strcmp(ent->d_name, ".."))
  1283. continue;
  1284. snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
  1285. e.name = name;
  1286. e.check = test__checkevent_pmu_events;
  1287. ret = test_event(&e);
  1288. #undef MAX_NAME
  1289. }
  1290. closedir(dir);
  1291. return ret;
  1292. }
  1293. int test__parse_events(void)
  1294. {
  1295. int ret1, ret2 = 0;
  1296. #define TEST_EVENTS(tests) \
  1297. do { \
  1298. ret1 = test_events(tests, ARRAY_SIZE(tests)); \
  1299. if (!ret2) \
  1300. ret2 = ret1; \
  1301. } while (0)
  1302. TEST_EVENTS(test__events);
  1303. if (test_pmu())
  1304. TEST_EVENTS(test__events_pmu);
  1305. if (test_pmu()) {
  1306. int ret = test_pmu_events();
  1307. if (ret)
  1308. return ret;
  1309. }
  1310. ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
  1311. if (!ret2)
  1312. ret2 = ret1;
  1313. return ret2;
  1314. }