parse-events.c 48 KB

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