parse-events.c 63 KB

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