parse-events.c 58 KB

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