parse-events.c 63 KB

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