parse-events.c 55 KB

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