parse-events.c 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "parse-events.h"
  3. #include "evsel.h"
  4. #include "evsel_fprintf.h"
  5. #include "evlist.h"
  6. #include <api/fs/fs.h>
  7. #include "tests.h"
  8. #include "debug.h"
  9. #include "pmu.h"
  10. #include "pmus.h"
  11. #include "strbuf.h"
  12. #include <dirent.h>
  13. #include <errno.h>
  14. #include "fncache.h"
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <unistd.h>
  18. #include <linux/kernel.h>
  19. #include <linux/hw_breakpoint.h>
  20. #include <api/fs/tracing_path.h>
  21. #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
  22. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
  23. static bool check_evlist(const char *test, int line, bool cond, struct evlist *evlist)
  24. {
  25. struct strbuf sb = STRBUF_INIT;
  26. if (cond)
  27. return true;
  28. evlist__format_evsels(evlist, &sb, 2048);
  29. pr_debug("FAILED %s:%d: %s\nFor evlist: %s\n", __FILE__, line, test, sb.buf);
  30. strbuf_release(&sb);
  31. return false;
  32. }
  33. #define TEST_ASSERT_EVLIST(test, cond, evlist) \
  34. if (!check_evlist(test, __LINE__, cond, evlist)) \
  35. return TEST_FAIL
  36. static bool check_evsel(const char *test, int line, bool cond, struct evsel *evsel)
  37. {
  38. struct perf_attr_details details = { .verbose = true, };
  39. if (cond)
  40. return true;
  41. pr_debug("FAILED %s:%d: %s\nFor evsel: ", __FILE__, line, test);
  42. evsel__fprintf(evsel, &details, debug_file());
  43. return false;
  44. }
  45. #define TEST_ASSERT_EVSEL(test, cond, evsel) \
  46. if (!check_evsel(test, __LINE__, cond, evsel)) \
  47. return TEST_FAIL
  48. static int num_core_entries(struct evlist *evlist)
  49. {
  50. /*
  51. * Returns number of core PMUs if the evlist has >1 core PMU, otherwise
  52. * returns 1. The number of core PMUs is needed as wild carding can
  53. * open an event for each core PMU. If the events were opened with a
  54. * specified PMU then wild carding won't happen.
  55. */
  56. struct perf_pmu *core_pmu = NULL;
  57. struct evsel *evsel;
  58. evlist__for_each_entry(evlist, evsel) {
  59. if (!evsel->pmu->is_core)
  60. continue;
  61. if (core_pmu != evsel->pmu && core_pmu != NULL)
  62. return perf_pmus__num_core_pmus();
  63. core_pmu = evsel->pmu;
  64. }
  65. return 1;
  66. }
  67. static bool test_hw_config(const struct evsel *evsel, __u64 expected_config)
  68. {
  69. return (evsel->core.attr.config & PERF_HW_EVENT_MASK) == expected_config;
  70. }
  71. #if defined(__s390x__)
  72. /* Return true if kvm module is available and loaded. Test this
  73. * and return success when trace point kvm_s390_create_vm
  74. * exists. Otherwise this test always fails.
  75. */
  76. static bool kvm_s390_create_vm_valid(void)
  77. {
  78. char *eventfile;
  79. bool rc = false;
  80. eventfile = get_events_file("kvm-s390");
  81. if (eventfile) {
  82. DIR *mydir = opendir(eventfile);
  83. if (mydir) {
  84. rc = true;
  85. closedir(mydir);
  86. }
  87. put_events_file(eventfile);
  88. }
  89. return rc;
  90. }
  91. #endif
  92. static int test__checkevent_tracepoint(struct evlist *evlist)
  93. {
  94. struct evsel *evsel = evlist__first(evlist);
  95. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  96. TEST_ASSERT_EVLIST("wrong number of groups", 0 == evlist__nr_groups(evlist), evlist);
  97. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type, evsel);
  98. TEST_ASSERT_EVSEL("wrong sample_type",
  99. PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type, evsel);
  100. TEST_ASSERT_EVSEL("wrong sample_period", 1 == evsel->core.attr.sample_period, evsel);
  101. return TEST_OK;
  102. }
  103. static int test__checkevent_tracepoint_multi(struct evlist *evlist)
  104. {
  105. struct evsel *evsel;
  106. TEST_ASSERT_EVLIST("wrong number of entries", evlist->core.nr_entries > 1, evlist);
  107. TEST_ASSERT_EVLIST("wrong number of groups", 0 == evlist__nr_groups(evlist), evlist);
  108. evlist__for_each_entry(evlist, evsel) {
  109. TEST_ASSERT_EVSEL("wrong type",
  110. PERF_TYPE_TRACEPOINT == evsel->core.attr.type,
  111. evsel);
  112. TEST_ASSERT_EVSEL("wrong sample_type",
  113. PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type,
  114. evsel);
  115. TEST_ASSERT_EVSEL("wrong sample_period",
  116. 1 == evsel->core.attr.sample_period,
  117. evsel);
  118. }
  119. return TEST_OK;
  120. }
  121. static int test__checkevent_raw(struct evlist *evlist)
  122. {
  123. struct evsel *evsel;
  124. bool raw_type_match = false;
  125. TEST_ASSERT_EVLIST("wrong number of entries", 0 != evlist->core.nr_entries, evlist);
  126. evlist__for_each_entry(evlist, evsel) {
  127. struct perf_pmu *pmu __maybe_unused = NULL;
  128. bool type_matched = false;
  129. TEST_ASSERT_EVSEL("wrong config", test_hw_config(evsel, 0x1a), evsel);
  130. TEST_ASSERT_EVSEL("event not parsed as raw type",
  131. evsel->core.attr.type == PERF_TYPE_RAW,
  132. evsel);
  133. #if defined(__aarch64__)
  134. /*
  135. * Arm doesn't have a real raw type PMU in sysfs, so raw events
  136. * would never match any PMU. However, RAW events on Arm will
  137. * always successfully open on the first available core PMU
  138. * so no need to test for a matching type here.
  139. */
  140. type_matched = raw_type_match = true;
  141. #else
  142. while ((pmu = perf_pmus__scan(pmu)) != NULL) {
  143. if (pmu->type == evsel->core.attr.type) {
  144. TEST_ASSERT_EVSEL("PMU type expected once", !type_matched, evsel);
  145. type_matched = true;
  146. if (pmu->type == PERF_TYPE_RAW)
  147. raw_type_match = true;
  148. }
  149. }
  150. #endif
  151. TEST_ASSERT_EVSEL("No PMU found for type", type_matched, evsel);
  152. }
  153. TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match);
  154. return TEST_OK;
  155. }
  156. static int test__checkevent_numeric(struct evlist *evlist)
  157. {
  158. struct evsel *evsel = evlist__first(evlist);
  159. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  160. TEST_ASSERT_EVSEL("wrong type", 1 == evsel->core.attr.type, evsel);
  161. TEST_ASSERT_EVSEL("wrong config", 1 == evsel->core.attr.config, evsel);
  162. return TEST_OK;
  163. }
  164. static int test__checkevent_symbolic_name(struct evlist *evlist)
  165. {
  166. struct evsel *evsel;
  167. TEST_ASSERT_EVLIST("wrong number of entries", 0 != evlist->core.nr_entries, evlist);
  168. evlist__for_each_entry(evlist, evsel) {
  169. TEST_ASSERT_EVSEL("unexpected event",
  170. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  171. evsel);
  172. }
  173. return TEST_OK;
  174. }
  175. static int test__checkevent_symbolic_name_config(struct evlist *evlist)
  176. {
  177. struct evsel *evsel;
  178. TEST_ASSERT_EVLIST("wrong number of entries", 0 != evlist->core.nr_entries, evlist);
  179. evlist__for_each_entry(evlist, evsel) {
  180. TEST_ASSERT_EVSEL("unexpected event",
  181. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  182. evsel);
  183. /*
  184. * The period value gets configured within evlist__config,
  185. * while this test executes only parse events method.
  186. */
  187. TEST_ASSERT_EVSEL("wrong period", 0 == evsel->core.attr.sample_period, evsel);
  188. TEST_ASSERT_EVSEL("wrong config1", 0 == evsel->core.attr.config1, evsel);
  189. TEST_ASSERT_EVSEL("wrong config2", 1 == evsel->core.attr.config2, evsel);
  190. }
  191. return TEST_OK;
  192. }
  193. static int test__checkevent_symbolic_alias(struct evlist *evlist)
  194. {
  195. struct evsel *evsel = evlist__first(evlist);
  196. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  197. TEST_ASSERT_EVSEL("wrong type/config", evsel__match(evsel, SOFTWARE, SW_PAGE_FAULTS),
  198. evsel);
  199. return TEST_OK;
  200. }
  201. static int test__checkevent_genhw(struct evlist *evlist)
  202. {
  203. struct evsel *evsel;
  204. TEST_ASSERT_EVLIST("wrong number of entries", 0 != evlist->core.nr_entries, evlist);
  205. evlist__for_each_entry(evlist, evsel) {
  206. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type, evsel);
  207. TEST_ASSERT_EVSEL("wrong config", test_hw_config(evsel, 1 << 16), evsel);
  208. }
  209. return TEST_OK;
  210. }
  211. static int test__checkevent_breakpoint(struct evlist *evlist)
  212. {
  213. struct evsel *evsel = evlist__first(evlist);
  214. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  215. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  216. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  217. TEST_ASSERT_EVSEL("wrong bp_type",
  218. (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == evsel->core.attr.bp_type,
  219. evsel);
  220. TEST_ASSERT_EVSEL("wrong bp_len", HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len, evsel);
  221. return TEST_OK;
  222. }
  223. static int test__checkevent_breakpoint_x(struct evlist *evlist)
  224. {
  225. struct evsel *evsel = evlist__first(evlist);
  226. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  227. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  228. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  229. TEST_ASSERT_EVSEL("wrong bp_type", HW_BREAKPOINT_X == evsel->core.attr.bp_type, evsel);
  230. TEST_ASSERT_EVSEL("wrong bp_len", default_breakpoint_len() == evsel->core.attr.bp_len,
  231. evsel);
  232. return TEST_OK;
  233. }
  234. static int test__checkevent_breakpoint_r(struct evlist *evlist)
  235. {
  236. struct evsel *evsel = evlist__first(evlist);
  237. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  238. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  239. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  240. TEST_ASSERT_EVSEL("wrong bp_type", HW_BREAKPOINT_R == evsel->core.attr.bp_type, evsel);
  241. TEST_ASSERT_EVSEL("wrong bp_len", HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len, evsel);
  242. return TEST_OK;
  243. }
  244. static int test__checkevent_breakpoint_w(struct evlist *evlist)
  245. {
  246. struct evsel *evsel = evlist__first(evlist);
  247. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  248. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  249. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  250. TEST_ASSERT_EVSEL("wrong bp_type", HW_BREAKPOINT_W == evsel->core.attr.bp_type, evsel);
  251. TEST_ASSERT_EVSEL("wrong bp_len", HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len, evsel);
  252. return TEST_OK;
  253. }
  254. static int test__checkevent_breakpoint_rw(struct evlist *evlist)
  255. {
  256. struct evsel *evsel = evlist__first(evlist);
  257. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  258. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  259. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  260. TEST_ASSERT_EVSEL("wrong bp_type",
  261. (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type,
  262. evsel);
  263. TEST_ASSERT_EVSEL("wrong bp_len", HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len, evsel);
  264. return TEST_OK;
  265. }
  266. static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
  267. {
  268. struct evsel *evsel = evlist__first(evlist);
  269. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  270. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  271. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  272. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  273. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  274. return test__checkevent_tracepoint(evlist);
  275. }
  276. static int
  277. test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
  278. {
  279. struct evsel *evsel;
  280. TEST_ASSERT_EVLIST("wrong number of entries", evlist->core.nr_entries > 1, evlist);
  281. evlist__for_each_entry(evlist, evsel) {
  282. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  283. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  284. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  285. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  286. }
  287. return test__checkevent_tracepoint_multi(evlist);
  288. }
  289. static int test__checkevent_raw_modifier(struct evlist *evlist)
  290. {
  291. struct evsel *evsel;
  292. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  293. evlist__for_each_entry(evlist, evsel) {
  294. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  295. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  296. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  297. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  298. }
  299. return test__checkevent_raw(evlist);
  300. }
  301. static int test__checkevent_numeric_modifier(struct evlist *evlist)
  302. {
  303. struct evsel *evsel;
  304. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  305. evlist__for_each_entry(evlist, evsel) {
  306. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  307. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  308. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  309. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  310. }
  311. return test__checkevent_numeric(evlist);
  312. }
  313. static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
  314. {
  315. struct evsel *evsel;
  316. TEST_ASSERT_EVLIST("wrong number of entries",
  317. evlist->core.nr_entries == num_core_entries(evlist),
  318. evlist);
  319. evlist__for_each_entry(evlist, evsel) {
  320. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  321. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  322. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  323. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  324. }
  325. return test__checkevent_symbolic_name(evlist);
  326. }
  327. static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
  328. {
  329. struct evsel *evsel;
  330. TEST_ASSERT_EVLIST("wrong number of entries",
  331. evlist->core.nr_entries == num_core_entries(evlist),
  332. evlist);
  333. evlist__for_each_entry(evlist, evsel) {
  334. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  335. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  336. }
  337. return test__checkevent_symbolic_name(evlist);
  338. }
  339. static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
  340. {
  341. struct evsel *evsel;
  342. TEST_ASSERT_EVLIST("wrong number of entries",
  343. evlist->core.nr_entries == num_core_entries(evlist),
  344. evlist);
  345. evlist__for_each_entry(evlist, evsel) {
  346. TEST_ASSERT_EVSEL("wrong exclude guest", evsel->core.attr.exclude_guest, evsel);
  347. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  348. }
  349. return test__checkevent_symbolic_name(evlist);
  350. }
  351. static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
  352. {
  353. struct evsel *evsel = evlist__first(evlist);
  354. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  355. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  356. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  357. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  358. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  359. return test__checkevent_symbolic_alias(evlist);
  360. }
  361. static int test__checkevent_genhw_modifier(struct evlist *evlist)
  362. {
  363. struct evsel *evsel;
  364. TEST_ASSERT_EVLIST("wrong number of entries",
  365. evlist->core.nr_entries == num_core_entries(evlist),
  366. evlist);
  367. evlist__for_each_entry(evlist, evsel) {
  368. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  369. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  370. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  371. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  372. }
  373. return test__checkevent_genhw(evlist);
  374. }
  375. static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
  376. {
  377. struct evsel *evsel = evlist__first(evlist);
  378. TEST_ASSERT_EVLIST("wrong number of entries",
  379. evlist->core.nr_entries == num_core_entries(evlist),
  380. evlist);
  381. TEST_ASSERT_EVSEL("wrong exclude idle", evsel->core.attr.exclude_idle, evsel);
  382. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  383. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  384. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  385. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  386. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  387. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  388. return test__checkevent_symbolic_name(evlist);
  389. }
  390. static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
  391. {
  392. struct evsel *evsel = evlist__first(evlist);
  393. TEST_ASSERT_EVLIST("wrong number of entries",
  394. evlist->core.nr_entries == num_core_entries(evlist),
  395. evlist);
  396. TEST_ASSERT_EVSEL("wrong exclude idle", evsel->core.attr.exclude_idle, evsel);
  397. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  398. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  399. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  400. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  401. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  402. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  403. return test__checkevent_symbolic_name(evlist);
  404. }
  405. static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
  406. {
  407. struct evsel *evsel = evlist__first(evlist);
  408. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  409. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  410. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  411. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  412. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "mem:0:u"), evsel);
  413. return test__checkevent_breakpoint(evlist);
  414. }
  415. static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
  416. {
  417. struct evsel *evsel = evlist__first(evlist);
  418. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  419. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  420. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  421. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  422. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "mem:0:x:k"), evsel);
  423. return test__checkevent_breakpoint_x(evlist);
  424. }
  425. static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
  426. {
  427. struct evsel *evsel = evlist__first(evlist);
  428. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  429. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  430. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  431. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  432. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "mem:0:r:hp"), evsel);
  433. return test__checkevent_breakpoint_r(evlist);
  434. }
  435. static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
  436. {
  437. struct evsel *evsel = evlist__first(evlist);
  438. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  439. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  440. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  441. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  442. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "mem:0:w:up"), evsel);
  443. return test__checkevent_breakpoint_w(evlist);
  444. }
  445. static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
  446. {
  447. struct evsel *evsel = evlist__first(evlist);
  448. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  449. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  450. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  451. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  452. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "mem:0:rw:kp"), evsel);
  453. return test__checkevent_breakpoint_rw(evlist);
  454. }
  455. static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist)
  456. {
  457. struct evsel *evsel = evlist__first(evlist);
  458. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  459. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  460. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  461. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  462. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint"), evsel);
  463. return test__checkevent_breakpoint(evlist);
  464. }
  465. static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist)
  466. {
  467. struct evsel *evsel = evlist__first(evlist);
  468. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  469. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  470. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  471. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  472. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint"), evsel);
  473. return test__checkevent_breakpoint_x(evlist);
  474. }
  475. static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist)
  476. {
  477. struct evsel *evsel = evlist__first(evlist);
  478. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  479. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  480. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  481. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  482. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint"), evsel);
  483. return test__checkevent_breakpoint_r(evlist);
  484. }
  485. static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist)
  486. {
  487. struct evsel *evsel = evlist__first(evlist);
  488. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  489. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  490. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  491. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  492. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint"), evsel);
  493. return test__checkevent_breakpoint_w(evlist);
  494. }
  495. static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist)
  496. {
  497. struct evsel *evsel = evlist__first(evlist);
  498. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  499. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  500. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  501. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  502. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint"), evsel);
  503. return test__checkevent_breakpoint_rw(evlist);
  504. }
  505. static int test__checkevent_breakpoint_2_events(struct evlist *evlist)
  506. {
  507. struct evsel *evsel = evlist__first(evlist);
  508. TEST_ASSERT_EVSEL("wrong number of entries", 2 == evlist->core.nr_entries, evsel);
  509. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  510. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint1"), evsel);
  511. evsel = evsel__next(evsel);
  512. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  513. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "breakpoint2"), evsel);
  514. return TEST_OK;
  515. }
  516. static int test__checkevent_pmu(struct evlist *evlist)
  517. {
  518. struct evsel *evsel = evlist__first(evlist);
  519. struct perf_pmu *core_pmu = perf_pmus__find_core_pmu();
  520. TEST_ASSERT_EVSEL("wrong number of entries", 1 == evlist->core.nr_entries, evsel);
  521. TEST_ASSERT_EVSEL("wrong type", core_pmu->type == evsel->core.attr.type, evsel);
  522. TEST_ASSERT_EVSEL("wrong config", test_hw_config(evsel, 10), evsel);
  523. TEST_ASSERT_EVSEL("wrong config1", 1 == evsel->core.attr.config1, evsel);
  524. TEST_ASSERT_EVSEL("wrong config2", 3 == evsel->core.attr.config2, evsel);
  525. TEST_ASSERT_EVSEL("wrong config3", 0 == evsel->core.attr.config3, evsel);
  526. TEST_ASSERT_EVSEL("wrong config4", 0 == evsel->core.attr.config4, evsel);
  527. /*
  528. * The period value gets configured within evlist__config,
  529. * while this test executes only parse events method.
  530. */
  531. TEST_ASSERT_EVSEL("wrong period", 0 == evsel->core.attr.sample_period, evsel);
  532. return TEST_OK;
  533. }
  534. static int test__checkevent_list(struct evlist *evlist)
  535. {
  536. struct evsel *evsel = evlist__first(evlist);
  537. TEST_ASSERT_EVSEL("wrong number of entries", 3 <= evlist->core.nr_entries, evsel);
  538. /* r1 */
  539. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_TRACEPOINT != evsel->core.attr.type, evsel);
  540. while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
  541. TEST_ASSERT_EVSEL("wrong config", 1 == evsel->core.attr.config, evsel);
  542. TEST_ASSERT_EVSEL("wrong config1", 0 == evsel->core.attr.config1, evsel);
  543. TEST_ASSERT_EVSEL("wrong config2", 0 == evsel->core.attr.config2, evsel);
  544. TEST_ASSERT_EVSEL("wrong config3", 0 == evsel->core.attr.config3, evsel);
  545. TEST_ASSERT_EVSEL("wrong config4", 0 == evsel->core.attr.config4, evsel);
  546. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  547. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  548. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  549. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  550. evsel = evsel__next(evsel);
  551. }
  552. /* syscalls:sys_enter_openat:k */
  553. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type, evsel);
  554. TEST_ASSERT_EVSEL("wrong sample_type", PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type,
  555. evsel);
  556. TEST_ASSERT_EVSEL("wrong sample_period", 1 == evsel->core.attr.sample_period, evsel);
  557. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  558. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  559. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  560. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  561. /* 1:1:hp */
  562. evsel = evsel__next(evsel);
  563. TEST_ASSERT_EVSEL("wrong type", 1 == evsel->core.attr.type, evsel);
  564. TEST_ASSERT_EVSEL("wrong config", 1 == evsel->core.attr.config, evsel);
  565. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  566. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  567. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  568. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  569. return TEST_OK;
  570. }
  571. static int test__checkevent_pmu_name(struct evlist *evlist)
  572. {
  573. struct evsel *evsel = evlist__first(evlist);
  574. struct perf_pmu *core_pmu = perf_pmus__find_core_pmu();
  575. char buf[256];
  576. /* default_core/config=1,name=krava/u */
  577. TEST_ASSERT_EVLIST("wrong number of entries", 2 == evlist->core.nr_entries, evlist);
  578. TEST_ASSERT_EVSEL("wrong type", core_pmu->type == evsel->core.attr.type, evsel);
  579. TEST_ASSERT_EVSEL("wrong config", 1 == evsel->core.attr.config, evsel);
  580. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, "krava"), evsel);
  581. /* default_core/config=2/u" */
  582. evsel = evsel__next(evsel);
  583. TEST_ASSERT_EVSEL("wrong number of entries", 2 == evlist->core.nr_entries, evsel);
  584. TEST_ASSERT_EVSEL("wrong type", core_pmu->type == evsel->core.attr.type, evsel);
  585. TEST_ASSERT_EVSEL("wrong config", 2 == evsel->core.attr.config, evsel);
  586. snprintf(buf, sizeof(buf), "%s/config=2/u", core_pmu->name);
  587. TEST_ASSERT_EVSEL("wrong name", evsel__name_is(evsel, buf), evsel);
  588. return TEST_OK;
  589. }
  590. static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
  591. {
  592. struct evsel *evsel = evlist__first(evlist);
  593. struct perf_pmu *core_pmu = perf_pmus__find_core_pmu();
  594. /* default_core/config=1,call-graph=fp,time,period=100000/ */
  595. TEST_ASSERT_EVLIST("wrong number of entries", 2 == evlist->core.nr_entries, evlist);
  596. TEST_ASSERT_EVSEL("wrong type", core_pmu->type == evsel->core.attr.type, evsel);
  597. TEST_ASSERT_EVSEL("wrong config", 1 == evsel->core.attr.config, evsel);
  598. /*
  599. * The period, time and callgraph value gets configured within evlist__config,
  600. * while this test executes only parse events method.
  601. */
  602. TEST_ASSERT_EVSEL("wrong period", 0 == evsel->core.attr.sample_period, evsel);
  603. TEST_ASSERT_EVSEL("wrong callgraph", !evsel__has_callchain(evsel), evsel);
  604. TEST_ASSERT_EVSEL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type), evsel);
  605. /* default_core/config=2,call-graph=no,time=0,period=2000/ */
  606. evsel = evsel__next(evsel);
  607. TEST_ASSERT_EVSEL("wrong type", core_pmu->type == evsel->core.attr.type, evsel);
  608. TEST_ASSERT_EVSEL("wrong config", 2 == evsel->core.attr.config, evsel);
  609. /*
  610. * The period, time and callgraph value gets configured within evlist__config,
  611. * while this test executes only parse events method.
  612. */
  613. TEST_ASSERT_EVSEL("wrong period", 0 == evsel->core.attr.sample_period, evsel);
  614. TEST_ASSERT_EVSEL("wrong callgraph", !evsel__has_callchain(evsel), evsel);
  615. TEST_ASSERT_EVSEL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type), evsel);
  616. return TEST_OK;
  617. }
  618. static int test__checkevent_pmu_events(struct evlist *evlist)
  619. {
  620. struct evsel *evsel;
  621. struct perf_pmu *core_pmu = perf_pmus__find_core_pmu();
  622. TEST_ASSERT_EVLIST("wrong number of entries", 1 <= evlist->core.nr_entries, evlist);
  623. evlist__for_each_entry(evlist, evsel) {
  624. TEST_ASSERT_EVSEL("wrong type",
  625. core_pmu->type == evsel->core.attr.type ||
  626. !strncmp(evsel__name(evsel), evsel->pmu->name,
  627. strlen(evsel->pmu->name)),
  628. evsel);
  629. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  630. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  631. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  632. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  633. TEST_ASSERT_EVSEL("wrong pinned", !evsel->core.attr.pinned, evsel);
  634. TEST_ASSERT_EVSEL("wrong exclusive", !evsel->core.attr.exclusive, evsel);
  635. }
  636. return TEST_OK;
  637. }
  638. static int test__checkevent_pmu_events_mix(struct evlist *evlist)
  639. {
  640. struct evsel *evsel = NULL;
  641. /*
  642. * The wild card event will be opened at least once, but it may be
  643. * opened on each core PMU.
  644. */
  645. TEST_ASSERT_EVLIST("wrong number of entries", evlist->core.nr_entries >= 2, evlist);
  646. for (int i = 0; i < evlist->core.nr_entries - 1; i++) {
  647. evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  648. /* pmu-event:u */
  649. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  650. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  651. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  652. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  653. TEST_ASSERT_EVSEL("wrong pinned", !evsel->core.attr.pinned, evsel);
  654. TEST_ASSERT_EVSEL("wrong exclusive", !evsel->core.attr.exclusive, evsel);
  655. }
  656. /* default_core/pmu-event/u*/
  657. evsel = evsel__next(evsel);
  658. TEST_ASSERT_EVSEL("wrong type", evsel__find_pmu(evsel)->is_core, evsel);
  659. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  660. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  661. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  662. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  663. TEST_ASSERT_EVSEL("wrong pinned", !evsel->core.attr.pinned, evsel);
  664. TEST_ASSERT_EVSEL("wrong exclusive", !evsel->core.attr.pinned, evsel);
  665. return TEST_OK;
  666. }
  667. static int test__checkterms_simple(struct parse_events_terms *terms)
  668. {
  669. struct parse_events_term *term;
  670. /* config=10 */
  671. term = list_entry(terms->terms.next, struct parse_events_term, list);
  672. TEST_ASSERT_VAL("wrong type term",
  673. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
  674. TEST_ASSERT_VAL("wrong type val",
  675. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  676. TEST_ASSERT_VAL("wrong val", term->val.num == 10);
  677. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));
  678. /* config1 */
  679. term = list_entry(term->list.next, struct parse_events_term, list);
  680. TEST_ASSERT_VAL("wrong type term",
  681. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
  682. TEST_ASSERT_VAL("wrong type val",
  683. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  684. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  685. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1"));
  686. /* config2=3 */
  687. term = list_entry(term->list.next, struct parse_events_term, list);
  688. TEST_ASSERT_VAL("wrong type term",
  689. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
  690. TEST_ASSERT_VAL("wrong type val",
  691. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  692. TEST_ASSERT_VAL("wrong val", term->val.num == 3);
  693. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2"));
  694. /* config3=4 */
  695. term = list_entry(term->list.next, struct parse_events_term, list);
  696. TEST_ASSERT_VAL("wrong type term",
  697. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3);
  698. TEST_ASSERT_VAL("wrong type val",
  699. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  700. TEST_ASSERT_VAL("wrong val", term->val.num == 4);
  701. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config3"));
  702. /* config4=5 */
  703. term = list_entry(term->list.next, struct parse_events_term, list);
  704. TEST_ASSERT_VAL("wrong type term",
  705. term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG4);
  706. TEST_ASSERT_VAL("wrong type val",
  707. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  708. TEST_ASSERT_VAL("wrong val", term->val.num == 5);
  709. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config4"));
  710. /* umask=1*/
  711. term = list_entry(term->list.next, struct parse_events_term, list);
  712. TEST_ASSERT_VAL("wrong type term",
  713. term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
  714. TEST_ASSERT_VAL("wrong type val",
  715. term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
  716. TEST_ASSERT_VAL("wrong val", term->val.num == 1);
  717. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
  718. /*
  719. * read
  720. *
  721. * The perf_pmu__test_parse_init injects 'read' term into
  722. * perf_pmu_events_list, so 'read' is evaluated as read term
  723. * and not as raw event with 'ead' hex value.
  724. */
  725. term = list_entry(term->list.next, struct parse_events_term, list);
  726. TEST_ASSERT_VAL("wrong type term",
  727. term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
  728. TEST_ASSERT_VAL("wrong type val",
  729. term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
  730. TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "read"));
  731. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
  732. /*
  733. * r0xead
  734. *
  735. * To be still able to pass 'ead' value with 'r' syntax,
  736. * we added support to parse 'r0xHEX' event.
  737. */
  738. term = list_entry(term->list.next, struct parse_events_term, list);
  739. TEST_ASSERT_VAL("wrong type term",
  740. term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
  741. TEST_ASSERT_VAL("wrong type val",
  742. term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
  743. TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "r0xead"));
  744. TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
  745. return TEST_OK;
  746. }
  747. static int test__group1(struct evlist *evlist)
  748. {
  749. struct evsel *evsel = NULL, *leader;
  750. TEST_ASSERT_EVLIST("wrong number of entries",
  751. evlist->core.nr_entries == (num_core_entries(evlist) * 2),
  752. evlist);
  753. TEST_ASSERT_EVLIST("wrong number of groups",
  754. evlist__nr_groups(evlist) == num_core_entries(evlist),
  755. evlist);
  756. for (int i = 0; i < num_core_entries(evlist); i++) {
  757. /* instructions:k */
  758. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  759. TEST_ASSERT_EVSEL("unexpected event",
  760. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  761. evsel);
  762. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  763. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  764. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  765. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  766. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  767. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  768. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  769. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  770. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  771. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  772. /* cycles:upp */
  773. evsel = evsel__next(evsel);
  774. TEST_ASSERT_EVSEL("unexpected event", evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  775. evsel);
  776. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  777. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  778. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  779. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  780. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  781. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip == 2, evsel);
  782. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  783. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  784. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  785. }
  786. return TEST_OK;
  787. }
  788. static int test__group2(struct evlist *evlist)
  789. {
  790. struct evsel *evsel, *leader = NULL;
  791. TEST_ASSERT_EVLIST("wrong number of entries",
  792. evlist->core.nr_entries == (2 * num_core_entries(evlist) + 1),
  793. evlist);
  794. /*
  795. * TODO: Currently the software event won't be grouped with the hardware
  796. * event except for 1 PMU.
  797. */
  798. TEST_ASSERT_EVLIST("wrong number of groups", 1 == evlist__nr_groups(evlist), evlist);
  799. evlist__for_each_entry(evlist, evsel) {
  800. if (evsel__match(evsel, SOFTWARE, SW_PAGE_FAULTS)) {
  801. /* faults + :ku modifier */
  802. leader = evsel;
  803. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user,
  804. evsel);
  805. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel,
  806. evsel);
  807. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  808. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest,
  809. evsel);
  810. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host,
  811. evsel);
  812. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  813. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  814. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2,
  815. evsel);
  816. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  817. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  818. continue;
  819. }
  820. if (evsel__match(evsel, HARDWARE, HW_BRANCH_INSTRUCTIONS)) {
  821. /* branches + :u modifier */
  822. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user,
  823. evsel);
  824. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel,
  825. evsel);
  826. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  827. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest,
  828. evsel);
  829. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host,
  830. evsel);
  831. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  832. if (evsel__has_leader(evsel, leader)) {
  833. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1,
  834. evsel);
  835. }
  836. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  837. continue;
  838. }
  839. /* cycles:k */
  840. TEST_ASSERT_EVSEL("unexpected event", evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  841. evsel);
  842. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  843. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  844. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  845. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  846. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  847. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  848. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  849. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  850. }
  851. return TEST_OK;
  852. }
  853. static int test__group3(struct evlist *evlist __maybe_unused)
  854. {
  855. struct evsel *evsel, *group1_leader = NULL, *group2_leader = NULL;
  856. TEST_ASSERT_EVLIST("wrong number of entries",
  857. evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus() + 2),
  858. evlist);
  859. /*
  860. * Currently the software event won't be grouped with the hardware event
  861. * except for 1 PMU. This means there are always just 2 groups
  862. * regardless of the number of core PMUs.
  863. */
  864. TEST_ASSERT_EVLIST("wrong number of groups", 2 == evlist__nr_groups(evlist), evlist);
  865. evlist__for_each_entry(evlist, evsel) {
  866. if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
  867. /* group1 syscalls:sys_enter_openat:H */
  868. group1_leader = evsel;
  869. TEST_ASSERT_EVSEL("wrong sample_type",
  870. evsel->core.attr.sample_type == PERF_TP_SAMPLE_TYPE,
  871. evsel);
  872. TEST_ASSERT_EVSEL("wrong sample_period",
  873. 1 == evsel->core.attr.sample_period,
  874. evsel);
  875. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user,
  876. evsel);
  877. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel,
  878. evsel);
  879. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  880. TEST_ASSERT_EVSEL("wrong exclude guest", evsel->core.attr.exclude_guest,
  881. evsel);
  882. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host,
  883. evsel);
  884. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  885. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  886. TEST_ASSERT_EVSEL("wrong group name", !strcmp(evsel->group_name, "group1"),
  887. evsel);
  888. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2,
  889. evsel);
  890. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  891. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  892. continue;
  893. }
  894. if (evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
  895. if (evsel->core.attr.exclude_user) {
  896. /* group1 cycles:kppp */
  897. TEST_ASSERT_EVSEL("wrong exclude_user",
  898. evsel->core.attr.exclude_user, evsel);
  899. TEST_ASSERT_EVSEL("wrong exclude_kernel",
  900. !evsel->core.attr.exclude_kernel, evsel);
  901. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv,
  902. evsel);
  903. TEST_ASSERT_EVSEL("wrong exclude guest",
  904. !evsel->core.attr.exclude_guest, evsel);
  905. TEST_ASSERT_EVSEL("wrong exclude host",
  906. !evsel->core.attr.exclude_host, evsel);
  907. TEST_ASSERT_EVSEL("wrong precise_ip",
  908. evsel->core.attr.precise_ip == 3, evsel);
  909. if (evsel__has_leader(evsel, group1_leader)) {
  910. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name,
  911. evsel);
  912. TEST_ASSERT_EVSEL("wrong group_idx",
  913. evsel__group_idx(evsel) == 1,
  914. evsel);
  915. }
  916. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  917. } else {
  918. /* group2 cycles + G modifier */
  919. group2_leader = evsel;
  920. TEST_ASSERT_EVSEL("wrong exclude_kernel",
  921. !evsel->core.attr.exclude_kernel, evsel);
  922. TEST_ASSERT_EVSEL("wrong exclude_hv",
  923. !evsel->core.attr.exclude_hv, evsel);
  924. TEST_ASSERT_EVSEL("wrong exclude guest",
  925. !evsel->core.attr.exclude_guest, evsel);
  926. TEST_ASSERT_EVSEL("wrong exclude host",
  927. evsel->core.attr.exclude_host, evsel);
  928. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip,
  929. evsel);
  930. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel),
  931. evsel);
  932. if (evsel->core.nr_members == 2) {
  933. TEST_ASSERT_EVSEL("wrong group_idx",
  934. evsel__group_idx(evsel) == 0,
  935. evsel);
  936. }
  937. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  938. }
  939. continue;
  940. }
  941. if (evsel->core.attr.type == 1) {
  942. /* group2 1:3 + G modifier */
  943. TEST_ASSERT_EVSEL("wrong config", 3 == evsel->core.attr.config, evsel);
  944. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user,
  945. evsel);
  946. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel,
  947. evsel);
  948. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  949. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest,
  950. evsel);
  951. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host,
  952. evsel);
  953. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  954. if (evsel__has_leader(evsel, group2_leader)) {
  955. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1,
  956. evsel);
  957. }
  958. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  959. continue;
  960. }
  961. /* instructions:u */
  962. TEST_ASSERT_EVSEL("unexpected event",
  963. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  964. evsel);
  965. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  966. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  967. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  968. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  969. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  970. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  971. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  972. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  973. }
  974. return TEST_OK;
  975. }
  976. static int test__group4(struct evlist *evlist __maybe_unused)
  977. {
  978. struct evsel *evsel = NULL, *leader;
  979. TEST_ASSERT_EVLIST("wrong number of entries",
  980. evlist->core.nr_entries == (num_core_entries(evlist) * 2),
  981. evlist);
  982. TEST_ASSERT_EVLIST("wrong number of groups",
  983. num_core_entries(evlist) == evlist__nr_groups(evlist),
  984. evlist);
  985. for (int i = 0; i < num_core_entries(evlist); i++) {
  986. /* cycles:u + p */
  987. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  988. TEST_ASSERT_EVSEL("unexpected event",
  989. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  990. evsel);
  991. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  992. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  993. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  994. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  995. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  996. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip == 1, evsel);
  997. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  998. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  999. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1000. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1001. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  1002. /* instructions:kp + p */
  1003. evsel = evsel__next(evsel);
  1004. TEST_ASSERT_EVSEL("unexpected event",
  1005. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  1006. evsel);
  1007. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  1008. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1009. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1010. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1011. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1012. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip == 2, evsel);
  1013. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1014. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1015. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  1016. }
  1017. return TEST_OK;
  1018. }
  1019. static int test__group5(struct evlist *evlist __maybe_unused)
  1020. {
  1021. struct evsel *evsel = NULL, *leader;
  1022. TEST_ASSERT_EVLIST("wrong number of entries",
  1023. evlist->core.nr_entries == (5 * num_core_entries(evlist)),
  1024. evlist);
  1025. TEST_ASSERT_EVLIST("wrong number of groups",
  1026. evlist__nr_groups(evlist) == (2 * num_core_entries(evlist)),
  1027. evlist);
  1028. for (int i = 0; i < num_core_entries(evlist); i++) {
  1029. /* cycles + G */
  1030. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1031. TEST_ASSERT_EVSEL("unexpected event",
  1032. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1033. evsel);
  1034. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1035. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1036. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1037. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1038. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1039. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1040. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1041. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1042. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1043. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1044. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  1045. /* instructions + G */
  1046. evsel = evsel__next(evsel);
  1047. TEST_ASSERT_EVSEL("unexpected event",
  1048. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  1049. evsel);
  1050. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1051. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1052. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1053. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1054. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1055. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1056. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1057. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1058. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  1059. }
  1060. for (int i = 0; i < num_core_entries(evlist); i++) {
  1061. /* cycles:G */
  1062. evsel = leader = evsel__next(evsel);
  1063. TEST_ASSERT_EVSEL("unexpected event",
  1064. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1065. evsel);
  1066. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1067. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1068. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1069. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1070. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1071. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1072. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1073. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1074. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1075. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1076. TEST_ASSERT_EVSEL("wrong sample_read", !evsel->sample_read, evsel);
  1077. /* instructions:G */
  1078. evsel = evsel__next(evsel);
  1079. TEST_ASSERT_EVSEL("unexpected event",
  1080. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  1081. evsel);
  1082. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1083. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1084. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1085. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1086. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1087. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1088. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1089. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1090. }
  1091. for (int i = 0; i < num_core_entries(evlist); i++) {
  1092. /* cycles */
  1093. evsel = evsel__next(evsel);
  1094. TEST_ASSERT_EVSEL("unexpected event",
  1095. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1096. evsel);
  1097. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1098. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1099. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1100. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1101. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1102. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1103. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1104. }
  1105. return TEST_OK;
  1106. }
  1107. static int test__group_gh1(struct evlist *evlist)
  1108. {
  1109. struct evsel *evsel = NULL, *leader;
  1110. TEST_ASSERT_EVLIST("wrong number of entries",
  1111. evlist->core.nr_entries == (2 * num_core_entries(evlist)),
  1112. evlist);
  1113. TEST_ASSERT_EVLIST("wrong number of groups",
  1114. evlist__nr_groups(evlist) == num_core_entries(evlist),
  1115. evlist);
  1116. for (int i = 0; i < num_core_entries(evlist); i++) {
  1117. /* cycles + :H group modifier */
  1118. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1119. TEST_ASSERT_EVSEL("unexpected event",
  1120. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1121. evsel);
  1122. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1123. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1124. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1125. TEST_ASSERT_EVSEL("wrong exclude guest", evsel->core.attr.exclude_guest, evsel);
  1126. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1127. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1128. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1129. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1130. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1131. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1132. /* cache-misses:G + :H group modifier */
  1133. evsel = evsel__next(evsel);
  1134. TEST_ASSERT_EVSEL("unexpected event",
  1135. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1136. evsel);
  1137. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1138. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1139. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1140. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1141. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1142. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1143. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1144. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1145. }
  1146. return TEST_OK;
  1147. }
  1148. static int test__group_gh2(struct evlist *evlist)
  1149. {
  1150. struct evsel *evsel = NULL, *leader;
  1151. TEST_ASSERT_EVLIST("wrong number of entries",
  1152. evlist->core.nr_entries == (2 * num_core_entries(evlist)),
  1153. evlist);
  1154. TEST_ASSERT_EVLIST("wrong number of groups",
  1155. evlist__nr_groups(evlist) == num_core_entries(evlist),
  1156. evlist);
  1157. for (int i = 0; i < num_core_entries(evlist); i++) {
  1158. /* cycles + :G group modifier */
  1159. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1160. TEST_ASSERT_EVSEL("unexpected event",
  1161. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1162. evsel);
  1163. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1164. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1165. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1166. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1167. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1168. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1169. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1170. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1171. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1172. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1173. /* cache-misses:H + :G group modifier */
  1174. evsel = evsel__next(evsel);
  1175. TEST_ASSERT_EVSEL("unexpected event",
  1176. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1177. evsel);
  1178. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1179. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1180. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1181. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1182. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1183. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1184. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1185. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1186. }
  1187. return TEST_OK;
  1188. }
  1189. static int test__group_gh3(struct evlist *evlist)
  1190. {
  1191. struct evsel *evsel = NULL, *leader;
  1192. TEST_ASSERT_EVLIST("wrong number of entries",
  1193. evlist->core.nr_entries == (2 * num_core_entries(evlist)),
  1194. evlist);
  1195. TEST_ASSERT_EVLIST("wrong number of groups",
  1196. evlist__nr_groups(evlist) == num_core_entries(evlist),
  1197. evlist);
  1198. for (int i = 0; i < num_core_entries(evlist); i++) {
  1199. /* cycles:G + :u group modifier */
  1200. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1201. TEST_ASSERT_EVSEL("unexpected event",
  1202. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1203. evsel);
  1204. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1205. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1206. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1207. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1208. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1209. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1210. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1211. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1212. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1213. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1214. /* cache-misses:H + :u group modifier */
  1215. evsel = evsel__next(evsel);
  1216. TEST_ASSERT_EVSEL("unexpected event",
  1217. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1218. evsel);
  1219. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1220. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1221. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1222. TEST_ASSERT_EVSEL("wrong exclude guest", evsel->core.attr.exclude_guest, evsel);
  1223. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1224. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1225. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1226. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1227. }
  1228. return TEST_OK;
  1229. }
  1230. static int test__group_gh4(struct evlist *evlist)
  1231. {
  1232. struct evsel *evsel = NULL, *leader;
  1233. TEST_ASSERT_EVLIST("wrong number of entries",
  1234. evlist->core.nr_entries == (2 * num_core_entries(evlist)),
  1235. evlist);
  1236. TEST_ASSERT_EVLIST("wrong number of groups",
  1237. evlist__nr_groups(evlist) == num_core_entries(evlist),
  1238. evlist);
  1239. for (int i = 0; i < num_core_entries(evlist); i++) {
  1240. /* cycles:G + :uG group modifier */
  1241. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1242. TEST_ASSERT_EVSEL("unexpected event",
  1243. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1244. evsel);
  1245. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1246. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1247. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1248. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1249. TEST_ASSERT_EVSEL("wrong exclude host", evsel->core.attr.exclude_host, evsel);
  1250. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1251. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1252. TEST_ASSERT_EVSEL("wrong leader", evsel__is_group_leader(evsel), evsel);
  1253. TEST_ASSERT_EVSEL("wrong core.nr_members", evsel->core.nr_members == 2, evsel);
  1254. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 0, evsel);
  1255. /* cache-misses:H + :uG group modifier */
  1256. evsel = evsel__next(evsel);
  1257. TEST_ASSERT_EVSEL("unexpected event",
  1258. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1259. evsel);
  1260. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1261. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1262. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1263. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1264. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1265. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1266. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1267. TEST_ASSERT_EVSEL("wrong group_idx", evsel__group_idx(evsel) == 1, evsel);
  1268. }
  1269. return TEST_OK;
  1270. }
  1271. static int test__leader_sample1(struct evlist *evlist)
  1272. {
  1273. struct evsel *evsel = NULL, *leader;
  1274. TEST_ASSERT_EVLIST("wrong number of entries",
  1275. evlist->core.nr_entries == (3 * num_core_entries(evlist)),
  1276. evlist);
  1277. for (int i = 0; i < num_core_entries(evlist); i++) {
  1278. /* cycles - sampling group leader */
  1279. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1280. TEST_ASSERT_EVSEL("unexpected event",
  1281. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1282. evsel);
  1283. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1284. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1285. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1286. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1287. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1288. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1289. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1290. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1291. TEST_ASSERT_EVSEL("wrong sample_read", evsel->sample_read, evsel);
  1292. /* cache-misses - not sampling */
  1293. evsel = evsel__next(evsel);
  1294. TEST_ASSERT_EVSEL("unexpected event",
  1295. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1296. evsel);
  1297. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1298. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1299. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1300. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1301. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1302. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1303. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1304. TEST_ASSERT_EVSEL("wrong sample_read", evsel->sample_read, evsel);
  1305. /* branch-misses - not sampling */
  1306. evsel = evsel__next(evsel);
  1307. TEST_ASSERT_EVSEL("unexpected event",
  1308. evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES),
  1309. evsel);
  1310. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1311. TEST_ASSERT_EVSEL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel, evsel);
  1312. TEST_ASSERT_EVSEL("wrong exclude_hv", !evsel->core.attr.exclude_hv, evsel);
  1313. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1314. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1315. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1316. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1317. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1318. TEST_ASSERT_EVSEL("wrong sample_read", evsel->sample_read, evsel);
  1319. }
  1320. return TEST_OK;
  1321. }
  1322. static int test__leader_sample2(struct evlist *evlist __maybe_unused)
  1323. {
  1324. struct evsel *evsel = NULL, *leader;
  1325. TEST_ASSERT_EVLIST("wrong number of entries",
  1326. evlist->core.nr_entries == (2 * num_core_entries(evlist)),
  1327. evlist);
  1328. for (int i = 0; i < num_core_entries(evlist); i++) {
  1329. /* instructions - sampling group leader */
  1330. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1331. TEST_ASSERT_EVSEL("unexpected event",
  1332. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  1333. evsel);
  1334. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1335. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1336. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1337. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1338. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1339. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1340. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1341. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1342. TEST_ASSERT_EVSEL("wrong sample_read", evsel->sample_read, evsel);
  1343. /* branch-misses - not sampling */
  1344. evsel = evsel__next(evsel);
  1345. TEST_ASSERT_EVSEL("unexpected event",
  1346. evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES),
  1347. evsel);
  1348. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1349. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1350. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1351. TEST_ASSERT_EVSEL("wrong exclude guest", !evsel->core.attr.exclude_guest, evsel);
  1352. TEST_ASSERT_EVSEL("wrong exclude host", !evsel->core.attr.exclude_host, evsel);
  1353. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1354. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1355. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1356. TEST_ASSERT_EVSEL("wrong sample_read", evsel->sample_read, evsel);
  1357. }
  1358. return TEST_OK;
  1359. }
  1360. static int test__checkevent_pinned_modifier(struct evlist *evlist)
  1361. {
  1362. struct evsel *evsel = NULL;
  1363. TEST_ASSERT_EVLIST("wrong number of entries",
  1364. evlist->core.nr_entries == num_core_entries(evlist),
  1365. evlist);
  1366. for (int i = 0; i < num_core_entries(evlist); i++) {
  1367. evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1368. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1369. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1370. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1371. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  1372. TEST_ASSERT_EVSEL("wrong pinned", evsel->core.attr.pinned, evsel);
  1373. }
  1374. return test__checkevent_symbolic_name(evlist);
  1375. }
  1376. static int test__pinned_group(struct evlist *evlist)
  1377. {
  1378. struct evsel *evsel = NULL, *leader;
  1379. TEST_ASSERT_EVLIST("wrong number of entries",
  1380. evlist->core.nr_entries == (3 * num_core_entries(evlist)),
  1381. evlist);
  1382. for (int i = 0; i < num_core_entries(evlist); i++) {
  1383. /* cycles - group leader */
  1384. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1385. TEST_ASSERT_EVSEL("unexpected event",
  1386. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1387. evsel);
  1388. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1389. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1390. /* TODO: The group modifier is not copied to the split group leader. */
  1391. if (perf_pmus__num_core_pmus() == 1)
  1392. TEST_ASSERT_EVSEL("wrong pinned", evsel->core.attr.pinned, evsel);
  1393. /* cache-misses - can not be pinned, but will go on with the leader */
  1394. evsel = evsel__next(evsel);
  1395. TEST_ASSERT_EVSEL("unexpected event",
  1396. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1397. evsel);
  1398. TEST_ASSERT_EVSEL("wrong pinned", !evsel->core.attr.pinned, evsel);
  1399. /* branch-misses - ditto */
  1400. evsel = evsel__next(evsel);
  1401. TEST_ASSERT_EVSEL("unexpected event",
  1402. evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES),
  1403. evsel);
  1404. TEST_ASSERT_EVSEL("wrong pinned", !evsel->core.attr.pinned, evsel);
  1405. }
  1406. return TEST_OK;
  1407. }
  1408. static int test__checkevent_exclusive_modifier(struct evlist *evlist)
  1409. {
  1410. struct evsel *evsel = evlist__first(evlist);
  1411. TEST_ASSERT_EVLIST("wrong number of entries",
  1412. evlist->core.nr_entries == num_core_entries(evlist),
  1413. evlist);
  1414. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1415. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1416. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1417. TEST_ASSERT_EVSEL("wrong precise_ip", evsel->core.attr.precise_ip, evsel);
  1418. TEST_ASSERT_EVSEL("wrong exclusive", evsel->core.attr.exclusive, evsel);
  1419. return test__checkevent_symbolic_name(evlist);
  1420. }
  1421. static int test__exclusive_group(struct evlist *evlist)
  1422. {
  1423. struct evsel *evsel = NULL, *leader;
  1424. TEST_ASSERT_EVLIST("wrong number of entries",
  1425. evlist->core.nr_entries == 3 * num_core_entries(evlist),
  1426. evlist);
  1427. for (int i = 0; i < num_core_entries(evlist); i++) {
  1428. /* cycles - group leader */
  1429. evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
  1430. TEST_ASSERT_EVSEL("unexpected event",
  1431. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1432. evsel);
  1433. TEST_ASSERT_EVSEL("wrong group name", !evsel->group_name, evsel);
  1434. TEST_ASSERT_EVSEL("wrong leader", evsel__has_leader(evsel, leader), evsel);
  1435. /* TODO: The group modifier is not copied to the split group leader. */
  1436. if (perf_pmus__num_core_pmus() == 1)
  1437. TEST_ASSERT_EVSEL("wrong exclusive", evsel->core.attr.exclusive, evsel);
  1438. /* cache-misses - can not be pinned, but will go on with the leader */
  1439. evsel = evsel__next(evsel);
  1440. TEST_ASSERT_EVSEL("unexpected event",
  1441. evsel__match(evsel, HARDWARE, HW_CACHE_MISSES),
  1442. evsel);
  1443. TEST_ASSERT_EVSEL("wrong exclusive", !evsel->core.attr.exclusive, evsel);
  1444. /* branch-misses - ditto */
  1445. evsel = evsel__next(evsel);
  1446. TEST_ASSERT_EVSEL("unexpected event",
  1447. evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES),
  1448. evsel);
  1449. TEST_ASSERT_EVSEL("wrong exclusive", !evsel->core.attr.exclusive, evsel);
  1450. }
  1451. return TEST_OK;
  1452. }
  1453. static int test__checkevent_breakpoint_len(struct evlist *evlist)
  1454. {
  1455. struct evsel *evsel = evlist__first(evlist);
  1456. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1457. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  1458. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  1459. TEST_ASSERT_EVSEL("wrong bp_type",
  1460. (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == evsel->core.attr.bp_type,
  1461. evsel);
  1462. TEST_ASSERT_EVSEL("wrong bp_len", HW_BREAKPOINT_LEN_1 == evsel->core.attr.bp_len, evsel);
  1463. return TEST_OK;
  1464. }
  1465. static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
  1466. {
  1467. struct evsel *evsel = evlist__first(evlist);
  1468. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1469. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type, evsel);
  1470. TEST_ASSERT_EVSEL("wrong config", 0 == evsel->core.attr.config, evsel);
  1471. TEST_ASSERT_EVSEL("wrong bp_type", HW_BREAKPOINT_W == evsel->core.attr.bp_type, evsel);
  1472. TEST_ASSERT_EVSEL("wrong bp_len", HW_BREAKPOINT_LEN_2 == evsel->core.attr.bp_len, evsel);
  1473. return TEST_OK;
  1474. }
  1475. static int
  1476. test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
  1477. {
  1478. struct evsel *evsel = evlist__first(evlist);
  1479. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1480. TEST_ASSERT_EVSEL("wrong exclude_user", !evsel->core.attr.exclude_user, evsel);
  1481. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1482. TEST_ASSERT_EVSEL("wrong exclude_hv", evsel->core.attr.exclude_hv, evsel);
  1483. TEST_ASSERT_EVSEL("wrong precise_ip", !evsel->core.attr.precise_ip, evsel);
  1484. return test__checkevent_breakpoint_rw(evlist);
  1485. }
  1486. static int test__checkevent_precise_max_modifier(struct evlist *evlist)
  1487. {
  1488. struct evsel *evsel = evlist__first(evlist);
  1489. TEST_ASSERT_EVLIST("wrong number of entries",
  1490. evlist->core.nr_entries == 1 + num_core_entries(evlist),
  1491. evlist);
  1492. TEST_ASSERT_EVSEL("wrong type/config", evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK), evsel);
  1493. return TEST_OK;
  1494. }
  1495. static int test__checkevent_config_symbol(struct evlist *evlist)
  1496. {
  1497. struct evsel *evsel = evlist__first(evlist);
  1498. TEST_ASSERT_EVLIST("wrong number of entries",
  1499. evlist->core.nr_entries == num_core_entries(evlist),
  1500. evlist);
  1501. TEST_ASSERT_EVSEL("wrong name setting", evsel__name_is(evsel, "insn"), evsel);
  1502. return TEST_OK;
  1503. }
  1504. static int test__checkevent_config_raw(struct evlist *evlist)
  1505. {
  1506. struct evsel *evsel = evlist__first(evlist);
  1507. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1508. TEST_ASSERT_EVSEL("wrong name setting", evsel__name_is(evsel, "rawpmu"), evsel);
  1509. return TEST_OK;
  1510. }
  1511. static int test__checkevent_config_num(struct evlist *evlist)
  1512. {
  1513. struct evsel *evsel = evlist__first(evlist);
  1514. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1515. TEST_ASSERT_EVSEL("wrong name setting", evsel__name_is(evsel, "numpmu"), evsel);
  1516. return TEST_OK;
  1517. }
  1518. static int test__checkevent_config_cache(struct evlist *evlist)
  1519. {
  1520. struct evsel *evsel = evlist__first(evlist);
  1521. TEST_ASSERT_EVLIST("wrong number of entries",
  1522. evlist->core.nr_entries == num_core_entries(evlist),
  1523. evlist);
  1524. TEST_ASSERT_EVSEL("wrong name setting", evsel__name_is(evsel, "cachepmu"), evsel);
  1525. return test__checkevent_genhw(evlist);
  1526. }
  1527. static bool test__pmu_default_core_event_valid(void)
  1528. {
  1529. struct perf_pmu *pmu = perf_pmus__find_core_pmu();
  1530. if (!pmu)
  1531. return false;
  1532. return perf_pmu__has_format(pmu, "event");
  1533. }
  1534. static bool test__intel_pt_valid(void)
  1535. {
  1536. return !!perf_pmus__find("intel_pt");
  1537. }
  1538. static int test__intel_pt(struct evlist *evlist)
  1539. {
  1540. struct evsel *evsel = evlist__first(evlist);
  1541. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1542. TEST_ASSERT_EVSEL("wrong name setting", evsel__name_is(evsel, "intel_pt//u"), evsel);
  1543. return TEST_OK;
  1544. }
  1545. static bool test__acr_valid(void)
  1546. {
  1547. struct perf_pmu *pmu = NULL;
  1548. while ((pmu = perf_pmus__scan_core(pmu)) != NULL) {
  1549. if (perf_pmu__has_format(pmu, "acr_mask"))
  1550. return true;
  1551. }
  1552. return false;
  1553. }
  1554. static int test__ratio_to_prev(struct evlist *evlist)
  1555. {
  1556. struct evsel *evsel;
  1557. TEST_ASSERT_VAL("wrong number of entries", 2 * perf_pmus__num_core_pmus() == evlist->core.nr_entries);
  1558. evlist__for_each_entry(evlist, evsel) {
  1559. if (!perf_pmu__has_format(evsel->pmu, "acr_mask"))
  1560. return TEST_OK;
  1561. if (evsel == evlist__first(evlist)) {
  1562. TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
  1563. TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
  1564. TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
  1565. TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
  1566. TEST_ASSERT_EVSEL("unexpected event",
  1567. evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
  1568. evsel);
  1569. } else {
  1570. TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
  1571. TEST_ASSERT_VAL("wrong leader", !evsel__is_group_leader(evsel));
  1572. TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0);
  1573. TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
  1574. TEST_ASSERT_EVSEL("unexpected event",
  1575. evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
  1576. evsel);
  1577. }
  1578. /*
  1579. * The period value gets configured within evlist__config,
  1580. * while this test executes only parse events method.
  1581. */
  1582. TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
  1583. }
  1584. return TEST_OK;
  1585. }
  1586. static int test__checkevent_complex_name(struct evlist *evlist)
  1587. {
  1588. struct evsel *evsel = evlist__first(evlist);
  1589. TEST_ASSERT_EVLIST("wrong number of entries",
  1590. evlist->core.nr_entries == num_core_entries(evlist),
  1591. evlist);
  1592. TEST_ASSERT_EVSEL("wrong complex name parsing",
  1593. evsel__name_is(evsel,
  1594. "COMPLEX_CYCLES_NAME:orig=cpu-cycles,desc=chip-clock-ticks"),
  1595. evsel);
  1596. return TEST_OK;
  1597. }
  1598. static int test__checkevent_raw_pmu(struct evlist *evlist)
  1599. {
  1600. struct evsel *evsel = evlist__first(evlist);
  1601. TEST_ASSERT_EVLIST("wrong number of entries", 1 == evlist->core.nr_entries, evlist);
  1602. TEST_ASSERT_EVSEL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type, evsel);
  1603. TEST_ASSERT_EVSEL("wrong config", 0x1a == evsel->core.attr.config, evsel);
  1604. return TEST_OK;
  1605. }
  1606. static int test__sym_event_slash(struct evlist *evlist)
  1607. {
  1608. struct evsel *evsel = evlist__first(evlist);
  1609. TEST_ASSERT_EVLIST("wrong number of entries",
  1610. evlist->core.nr_entries == num_core_entries(evlist),
  1611. evlist);
  1612. TEST_ASSERT_EVSEL("unexpected event", evsel__match(evsel, HARDWARE, HW_CPU_CYCLES), evsel);
  1613. TEST_ASSERT_EVSEL("wrong exclude_kernel", evsel->core.attr.exclude_kernel, evsel);
  1614. return TEST_OK;
  1615. }
  1616. static int test__sym_event_dc(struct evlist *evlist)
  1617. {
  1618. struct evsel *evsel = evlist__first(evlist);
  1619. TEST_ASSERT_EVLIST("wrong number of entries",
  1620. evlist->core.nr_entries == num_core_entries(evlist),
  1621. evlist);
  1622. TEST_ASSERT_EVSEL("unexpected event", evsel__match(evsel, HARDWARE, HW_CPU_CYCLES), evsel);
  1623. TEST_ASSERT_EVSEL("wrong exclude_user", evsel->core.attr.exclude_user, evsel);
  1624. return TEST_OK;
  1625. }
  1626. static int test__term_equal_term(struct evlist *evlist)
  1627. {
  1628. struct evsel *evsel = evlist__first(evlist);
  1629. TEST_ASSERT_EVLIST("wrong number of entries",
  1630. evlist->core.nr_entries == num_core_entries(evlist),
  1631. evlist);
  1632. TEST_ASSERT_EVSEL("unexpected event", evsel__match(evsel, HARDWARE, HW_CPU_CYCLES), evsel);
  1633. TEST_ASSERT_EVSEL("wrong name setting", strcmp(evsel->name, "name") == 0, evsel);
  1634. return TEST_OK;
  1635. }
  1636. static int test__term_equal_legacy(struct evlist *evlist)
  1637. {
  1638. struct evsel *evsel = evlist__first(evlist);
  1639. TEST_ASSERT_EVLIST("wrong number of entries",
  1640. evlist->core.nr_entries == num_core_entries(evlist),
  1641. evlist);
  1642. TEST_ASSERT_EVSEL("unexpected event", evsel__match(evsel, HARDWARE, HW_CPU_CYCLES), evsel);
  1643. TEST_ASSERT_EVSEL("wrong name setting", strcmp(evsel->name, "l1d") == 0, evsel);
  1644. return TEST_OK;
  1645. }
  1646. static int count_tracepoints(void)
  1647. {
  1648. struct dirent *events_ent;
  1649. DIR *events_dir;
  1650. int cnt = 0;
  1651. events_dir = tracing_events__opendir();
  1652. TEST_ASSERT_VAL("Can't open events dir", events_dir);
  1653. while ((events_ent = readdir(events_dir))) {
  1654. char *sys_path;
  1655. struct dirent *sys_ent;
  1656. DIR *sys_dir;
  1657. if (!strcmp(events_ent->d_name, ".")
  1658. || !strcmp(events_ent->d_name, "..")
  1659. || !strcmp(events_ent->d_name, "enable")
  1660. || !strcmp(events_ent->d_name, "header_event")
  1661. || !strcmp(events_ent->d_name, "header_page"))
  1662. continue;
  1663. sys_path = get_events_file(events_ent->d_name);
  1664. TEST_ASSERT_VAL("Can't get sys path", sys_path);
  1665. sys_dir = opendir(sys_path);
  1666. TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
  1667. while ((sys_ent = readdir(sys_dir))) {
  1668. if (!strcmp(sys_ent->d_name, ".")
  1669. || !strcmp(sys_ent->d_name, "..")
  1670. || !strcmp(sys_ent->d_name, "enable")
  1671. || !strcmp(sys_ent->d_name, "filter"))
  1672. continue;
  1673. cnt++;
  1674. }
  1675. closedir(sys_dir);
  1676. put_events_file(sys_path);
  1677. }
  1678. closedir(events_dir);
  1679. return cnt;
  1680. }
  1681. static int test__all_tracepoints(struct evlist *evlist)
  1682. {
  1683. TEST_ASSERT_VAL("wrong events count",
  1684. count_tracepoints() == evlist->core.nr_entries);
  1685. return test__checkevent_tracepoint_multi(evlist);
  1686. }
  1687. struct evlist_test {
  1688. const char *name;
  1689. bool (*valid)(void);
  1690. int (*check)(struct evlist *evlist);
  1691. };
  1692. static const struct evlist_test test__events[] = {
  1693. {
  1694. .name = "syscalls:sys_enter_openat",
  1695. .check = test__checkevent_tracepoint,
  1696. /* 0 */
  1697. },
  1698. {
  1699. .name = "syscalls:*",
  1700. .check = test__checkevent_tracepoint_multi,
  1701. /* 1 */
  1702. },
  1703. {
  1704. .name = "r1a",
  1705. .check = test__checkevent_raw,
  1706. /* 2 */
  1707. },
  1708. {
  1709. .name = "1:1",
  1710. .check = test__checkevent_numeric,
  1711. /* 3 */
  1712. },
  1713. {
  1714. .name = "instructions",
  1715. .check = test__checkevent_symbolic_name,
  1716. /* 4 */
  1717. },
  1718. {
  1719. .name = "cpu-cycles/period=100000,config2/",
  1720. .check = test__checkevent_symbolic_name_config,
  1721. /* 5 */
  1722. },
  1723. {
  1724. .name = "faults",
  1725. .check = test__checkevent_symbolic_alias,
  1726. /* 6 */
  1727. },
  1728. {
  1729. .name = "L1-dcache-load-miss",
  1730. .check = test__checkevent_genhw,
  1731. /* 7 */
  1732. },
  1733. {
  1734. .name = "mem:0",
  1735. .check = test__checkevent_breakpoint,
  1736. /* 8 */
  1737. },
  1738. {
  1739. .name = "mem:0:x",
  1740. .check = test__checkevent_breakpoint_x,
  1741. /* 9 */
  1742. },
  1743. {
  1744. .name = "mem:0:r",
  1745. .check = test__checkevent_breakpoint_r,
  1746. /* 0 */
  1747. },
  1748. {
  1749. .name = "mem:0:w",
  1750. .check = test__checkevent_breakpoint_w,
  1751. /* 1 */
  1752. },
  1753. {
  1754. .name = "syscalls:sys_enter_openat:k",
  1755. .check = test__checkevent_tracepoint_modifier,
  1756. /* 2 */
  1757. },
  1758. {
  1759. .name = "syscalls:*:u",
  1760. .check = test__checkevent_tracepoint_multi_modifier,
  1761. /* 3 */
  1762. },
  1763. {
  1764. .name = "r1a:kp",
  1765. .check = test__checkevent_raw_modifier,
  1766. /* 4 */
  1767. },
  1768. {
  1769. .name = "1:1:hp",
  1770. .check = test__checkevent_numeric_modifier,
  1771. /* 5 */
  1772. },
  1773. {
  1774. .name = "instructions:h",
  1775. .check = test__checkevent_symbolic_name_modifier,
  1776. /* 6 */
  1777. },
  1778. {
  1779. .name = "faults:u",
  1780. .check = test__checkevent_symbolic_alias_modifier,
  1781. /* 7 */
  1782. },
  1783. {
  1784. .name = "L1-dcache-load-miss:kp",
  1785. .check = test__checkevent_genhw_modifier,
  1786. /* 8 */
  1787. },
  1788. {
  1789. .name = "mem:0:u",
  1790. .check = test__checkevent_breakpoint_modifier,
  1791. /* 9 */
  1792. },
  1793. {
  1794. .name = "mem:0:x:k",
  1795. .check = test__checkevent_breakpoint_x_modifier,
  1796. /* 0 */
  1797. },
  1798. {
  1799. .name = "mem:0:r:hp",
  1800. .check = test__checkevent_breakpoint_r_modifier,
  1801. /* 1 */
  1802. },
  1803. {
  1804. .name = "mem:0:w:up",
  1805. .check = test__checkevent_breakpoint_w_modifier,
  1806. /* 2 */
  1807. },
  1808. {
  1809. .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
  1810. .check = test__checkevent_list,
  1811. /* 3 */
  1812. },
  1813. {
  1814. .name = "instructions:G",
  1815. .check = test__checkevent_exclude_host_modifier,
  1816. /* 4 */
  1817. },
  1818. {
  1819. .name = "instructions:H",
  1820. .check = test__checkevent_exclude_guest_modifier,
  1821. /* 5 */
  1822. },
  1823. {
  1824. .name = "mem:0:rw",
  1825. .check = test__checkevent_breakpoint_rw,
  1826. /* 6 */
  1827. },
  1828. {
  1829. .name = "mem:0:rw:kp",
  1830. .check = test__checkevent_breakpoint_rw_modifier,
  1831. /* 7 */
  1832. },
  1833. {
  1834. .name = "{instructions:k,cpu-cycles:upp}",
  1835. .check = test__group1,
  1836. /* 8 */
  1837. },
  1838. {
  1839. .name = "{faults:k,branches}:u,cpu-cycles:k",
  1840. .check = test__group2,
  1841. /* 9 */
  1842. },
  1843. {
  1844. .name = "group1{syscalls:sys_enter_openat:H,cpu-cycles:kppp},group2{cpu-cycles,1:3}:G,instructions:u",
  1845. .check = test__group3,
  1846. /* 0 */
  1847. },
  1848. {
  1849. .name = "{cpu-cycles:u,instructions:kp}:p",
  1850. .check = test__group4,
  1851. /* 1 */
  1852. },
  1853. {
  1854. .name = "{cpu-cycles,instructions}:G,{cpu-cycles:G,instructions:G},cpu-cycles",
  1855. .check = test__group5,
  1856. /* 2 */
  1857. },
  1858. {
  1859. .name = "*:*",
  1860. .check = test__all_tracepoints,
  1861. /* 3 */
  1862. },
  1863. {
  1864. .name = "{cpu-cycles,cache-misses:G}:H",
  1865. .check = test__group_gh1,
  1866. /* 4 */
  1867. },
  1868. {
  1869. .name = "{cpu-cycles,cache-misses:H}:G",
  1870. .check = test__group_gh2,
  1871. /* 5 */
  1872. },
  1873. {
  1874. .name = "{cpu-cycles:G,cache-misses:H}:u",
  1875. .check = test__group_gh3,
  1876. /* 6 */
  1877. },
  1878. {
  1879. .name = "{cpu-cycles:G,cache-misses:H}:uG",
  1880. .check = test__group_gh4,
  1881. /* 7 */
  1882. },
  1883. {
  1884. .name = "{cpu-cycles,cache-misses,branch-misses}:S",
  1885. .check = test__leader_sample1,
  1886. /* 8 */
  1887. },
  1888. {
  1889. .name = "{instructions,branch-misses}:Su",
  1890. .check = test__leader_sample2,
  1891. /* 9 */
  1892. },
  1893. {
  1894. .name = "instructions:uDp",
  1895. .check = test__checkevent_pinned_modifier,
  1896. /* 0 */
  1897. },
  1898. {
  1899. .name = "{cpu-cycles,cache-misses,branch-misses}:D",
  1900. .check = test__pinned_group,
  1901. /* 1 */
  1902. },
  1903. {
  1904. .name = "mem:0/1",
  1905. .check = test__checkevent_breakpoint_len,
  1906. /* 2 */
  1907. },
  1908. {
  1909. .name = "mem:0/2:w",
  1910. .check = test__checkevent_breakpoint_len_w,
  1911. /* 3 */
  1912. },
  1913. {
  1914. .name = "mem:0/4:rw:u",
  1915. .check = test__checkevent_breakpoint_len_rw_modifier,
  1916. /* 4 */
  1917. },
  1918. #if defined(__s390x__)
  1919. {
  1920. .name = "kvm-s390:kvm_s390_create_vm",
  1921. .check = test__checkevent_tracepoint,
  1922. .valid = kvm_s390_create_vm_valid,
  1923. /* 0 */
  1924. },
  1925. #endif
  1926. {
  1927. .name = "instructions:I",
  1928. .check = test__checkevent_exclude_idle_modifier,
  1929. /* 5 */
  1930. },
  1931. {
  1932. .name = "instructions:kIG",
  1933. .check = test__checkevent_exclude_idle_modifier_1,
  1934. /* 6 */
  1935. },
  1936. {
  1937. .name = "task-clock:P,cpu-cycles",
  1938. .check = test__checkevent_precise_max_modifier,
  1939. /* 7 */
  1940. },
  1941. {
  1942. .name = "instructions/name=insn/",
  1943. .check = test__checkevent_config_symbol,
  1944. /* 8 */
  1945. },
  1946. {
  1947. .name = "r1234/name=rawpmu/",
  1948. .check = test__checkevent_config_raw,
  1949. /* 9 */
  1950. },
  1951. {
  1952. .name = "4:0x6530160/name=numpmu/",
  1953. .check = test__checkevent_config_num,
  1954. /* 0 */
  1955. },
  1956. {
  1957. .name = "L1-dcache-misses/name=cachepmu/",
  1958. .check = test__checkevent_config_cache,
  1959. /* 1 */
  1960. },
  1961. {
  1962. .name = "intel_pt//u",
  1963. .valid = test__intel_pt_valid,
  1964. .check = test__intel_pt,
  1965. /* 2 */
  1966. },
  1967. {
  1968. .name = "cpu-cycles/name='COMPLEX_CYCLES_NAME:orig=cpu-cycles,desc=chip-clock-ticks'/Duk",
  1969. .check = test__checkevent_complex_name,
  1970. /* 3 */
  1971. },
  1972. {
  1973. .name = "cpu-cycles//u",
  1974. .check = test__sym_event_slash,
  1975. /* 4 */
  1976. },
  1977. {
  1978. .name = "cpu-cycles:k",
  1979. .check = test__sym_event_dc,
  1980. /* 5 */
  1981. },
  1982. {
  1983. .name = "instructions:uep",
  1984. .check = test__checkevent_exclusive_modifier,
  1985. /* 6 */
  1986. },
  1987. {
  1988. .name = "{cpu-cycles,cache-misses,branch-misses}:e",
  1989. .check = test__exclusive_group,
  1990. /* 7 */
  1991. },
  1992. {
  1993. .name = "cpu-cycles/name=name/",
  1994. .check = test__term_equal_term,
  1995. /* 8 */
  1996. },
  1997. {
  1998. .name = "cpu-cycles/name=l1d/",
  1999. .check = test__term_equal_legacy,
  2000. /* 9 */
  2001. },
  2002. {
  2003. .name = "mem:0/name=breakpoint/",
  2004. .check = test__checkevent_breakpoint,
  2005. /* 0 */
  2006. },
  2007. {
  2008. .name = "mem:0:x/name=breakpoint/",
  2009. .check = test__checkevent_breakpoint_x,
  2010. /* 1 */
  2011. },
  2012. {
  2013. .name = "mem:0:r/name=breakpoint/",
  2014. .check = test__checkevent_breakpoint_r,
  2015. /* 2 */
  2016. },
  2017. {
  2018. .name = "mem:0:w/name=breakpoint/",
  2019. .check = test__checkevent_breakpoint_w,
  2020. /* 3 */
  2021. },
  2022. {
  2023. .name = "mem:0/name=breakpoint/u",
  2024. .check = test__checkevent_breakpoint_modifier_name,
  2025. /* 4 */
  2026. },
  2027. {
  2028. .name = "mem:0:x/name=breakpoint/k",
  2029. .check = test__checkevent_breakpoint_x_modifier_name,
  2030. /* 5 */
  2031. },
  2032. {
  2033. .name = "mem:0:r/name=breakpoint/hp",
  2034. .check = test__checkevent_breakpoint_r_modifier_name,
  2035. /* 6 */
  2036. },
  2037. {
  2038. .name = "mem:0:w/name=breakpoint/up",
  2039. .check = test__checkevent_breakpoint_w_modifier_name,
  2040. /* 7 */
  2041. },
  2042. {
  2043. .name = "mem:0:rw/name=breakpoint/",
  2044. .check = test__checkevent_breakpoint_rw,
  2045. /* 8 */
  2046. },
  2047. {
  2048. .name = "mem:0:rw/name=breakpoint/kp",
  2049. .check = test__checkevent_breakpoint_rw_modifier_name,
  2050. /* 9 */
  2051. },
  2052. {
  2053. .name = "mem:0/1/name=breakpoint/",
  2054. .check = test__checkevent_breakpoint_len,
  2055. /* 0 */
  2056. },
  2057. {
  2058. .name = "mem:0/2:w/name=breakpoint/",
  2059. .check = test__checkevent_breakpoint_len_w,
  2060. /* 1 */
  2061. },
  2062. {
  2063. .name = "mem:0/4:rw/name=breakpoint/u",
  2064. .check = test__checkevent_breakpoint_len_rw_modifier,
  2065. /* 2 */
  2066. },
  2067. {
  2068. .name = "mem:0/1/name=breakpoint1/,mem:0/4:rw/name=breakpoint2/",
  2069. .check = test__checkevent_breakpoint_2_events,
  2070. /* 3 */
  2071. },
  2072. {
  2073. .name = "9p:9p_client_req",
  2074. .check = test__checkevent_tracepoint,
  2075. /* 4 */
  2076. },
  2077. {
  2078. .name = "{cycles,instructions/period=200000,ratio-to-prev=2.0/}",
  2079. .valid = test__acr_valid,
  2080. .check = test__ratio_to_prev,
  2081. /* 5 */
  2082. },
  2083. };
  2084. static const struct evlist_test test__events_pmu[] = {
  2085. {
  2086. .name = "default_core/config=10,config1=1,config2=3,period=1000/u",
  2087. .check = test__checkevent_pmu,
  2088. /* 0 */
  2089. },
  2090. {
  2091. .name = "default_core/config=1,name=krava/u,default_core/config=2/u",
  2092. .check = test__checkevent_pmu_name,
  2093. /* 1 */
  2094. },
  2095. {
  2096. .name = "default_core/config=1,call-graph=fp,time,period=100000/,default_core/config=2,call-graph=no,time=0,period=2000/",
  2097. .check = test__checkevent_pmu_partial_time_callgraph,
  2098. /* 2 */
  2099. },
  2100. {
  2101. .name = "default_core/name='COMPLEX_CYCLES_NAME:orig=cpu-cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
  2102. .valid = test__pmu_default_core_event_valid,
  2103. .check = test__checkevent_complex_name,
  2104. /* 3 */
  2105. },
  2106. {
  2107. .name = "software/r1a/",
  2108. .check = test__checkevent_raw_pmu,
  2109. /* 4 */
  2110. },
  2111. {
  2112. .name = "software/r0x1a/",
  2113. .check = test__checkevent_raw_pmu,
  2114. /* 5 */
  2115. },
  2116. {
  2117. .name = "default_core/L1-dcache-load-miss/",
  2118. .check = test__checkevent_genhw,
  2119. /* 6 */
  2120. },
  2121. {
  2122. .name = "default_core/L1-dcache-load-miss/kp",
  2123. .check = test__checkevent_genhw_modifier,
  2124. /* 7 */
  2125. },
  2126. {
  2127. .name = "default_core/L1-dcache-misses,name=cachepmu/",
  2128. .check = test__checkevent_config_cache,
  2129. /* 8 */
  2130. },
  2131. {
  2132. .name = "default_core/instructions/",
  2133. .check = test__checkevent_symbolic_name,
  2134. /* 9 */
  2135. },
  2136. {
  2137. .name = "default_core/cycles,period=100000,config2/",
  2138. .check = test__checkevent_symbolic_name_config,
  2139. /* 0 */
  2140. },
  2141. {
  2142. .name = "default_core/instructions/h",
  2143. .check = test__checkevent_symbolic_name_modifier,
  2144. /* 1 */
  2145. },
  2146. {
  2147. .name = "default_core/instructions/G",
  2148. .check = test__checkevent_exclude_host_modifier,
  2149. /* 2 */
  2150. },
  2151. {
  2152. .name = "default_core/instructions/H",
  2153. .check = test__checkevent_exclude_guest_modifier,
  2154. /* 3 */
  2155. },
  2156. {
  2157. .name = "{default_core/instructions/k,default_core/cycles/upp}",
  2158. .check = test__group1,
  2159. /* 4 */
  2160. },
  2161. {
  2162. .name = "{default_core/cycles/u,default_core/instructions/kp}:p",
  2163. .check = test__group4,
  2164. /* 5 */
  2165. },
  2166. {
  2167. .name = "{default_core/cycles/,default_core/cache-misses/G}:H",
  2168. .check = test__group_gh1,
  2169. /* 6 */
  2170. },
  2171. {
  2172. .name = "{default_core/cycles/,default_core/cache-misses/H}:G",
  2173. .check = test__group_gh2,
  2174. /* 7 */
  2175. },
  2176. {
  2177. .name = "{default_core/cycles/G,default_core/cache-misses/H}:u",
  2178. .check = test__group_gh3,
  2179. /* 8 */
  2180. },
  2181. {
  2182. .name = "{default_core/cycles/G,default_core/cache-misses/H}:uG",
  2183. .check = test__group_gh4,
  2184. /* 9 */
  2185. },
  2186. {
  2187. .name = "{default_core/cycles/,default_core/cache-misses/,default_core/branch-misses/}:S",
  2188. .check = test__leader_sample1,
  2189. /* 0 */
  2190. },
  2191. {
  2192. .name = "{default_core/instructions/,default_core/branch-misses/}:Su",
  2193. .check = test__leader_sample2,
  2194. /* 1 */
  2195. },
  2196. {
  2197. .name = "default_core/instructions/uDp",
  2198. .check = test__checkevent_pinned_modifier,
  2199. /* 2 */
  2200. },
  2201. {
  2202. .name = "{default_core/cycles/,default_core/cache-misses/,default_core/branch-misses/}:D",
  2203. .check = test__pinned_group,
  2204. /* 3 */
  2205. },
  2206. {
  2207. .name = "default_core/instructions/I",
  2208. .check = test__checkevent_exclude_idle_modifier,
  2209. /* 4 */
  2210. },
  2211. {
  2212. .name = "default_core/instructions/kIG",
  2213. .check = test__checkevent_exclude_idle_modifier_1,
  2214. /* 5 */
  2215. },
  2216. {
  2217. .name = "default_core/cycles/u",
  2218. .check = test__sym_event_slash,
  2219. /* 6 */
  2220. },
  2221. {
  2222. .name = "default_core/cycles/k",
  2223. .check = test__sym_event_dc,
  2224. /* 7 */
  2225. },
  2226. {
  2227. .name = "default_core/instructions/uep",
  2228. .check = test__checkevent_exclusive_modifier,
  2229. /* 8 */
  2230. },
  2231. {
  2232. .name = "{default_core/cycles/,default_core/cache-misses/,default_core/branch-misses/}:e",
  2233. .check = test__exclusive_group,
  2234. /* 9 */
  2235. },
  2236. {
  2237. .name = "default_core/cycles,name=name/",
  2238. .check = test__term_equal_term,
  2239. /* 0 */
  2240. },
  2241. {
  2242. .name = "default_core/cycles,name=l1d/",
  2243. .check = test__term_equal_legacy,
  2244. /* 1 */
  2245. },
  2246. };
  2247. struct terms_test {
  2248. const char *str;
  2249. int (*check)(struct parse_events_terms *terms);
  2250. };
  2251. static const struct terms_test test__terms[] = {
  2252. [0] = {
  2253. .str = "config=10,config1,config2=3,config3=4,config4=5,umask=1,read,r0xead",
  2254. .check = test__checkterms_simple,
  2255. },
  2256. };
  2257. static int test_event(const struct evlist_test *e)
  2258. {
  2259. struct parse_events_error err;
  2260. struct evlist *evlist;
  2261. int ret;
  2262. if (e->valid && !e->valid()) {
  2263. pr_debug("... SKIP\n");
  2264. return TEST_OK;
  2265. }
  2266. evlist = evlist__new();
  2267. if (evlist == NULL) {
  2268. pr_err("Failed allocation");
  2269. return TEST_FAIL;
  2270. }
  2271. parse_events_error__init(&err);
  2272. ret = __parse_events(evlist, e->name, /*pmu_filter=*/NULL, &err, /*fake_pmu=*/false,
  2273. /*warn_if_reordered=*/true, /*fake_tp=*/true);
  2274. if (ret) {
  2275. pr_debug("failed to parse event '%s', err %d\n", e->name, ret);
  2276. parse_events_error__print(&err, e->name);
  2277. ret = TEST_FAIL;
  2278. if (parse_events_error__contains(&err, "can't access trace events"))
  2279. ret = TEST_SKIP;
  2280. } else {
  2281. ret = e->check(evlist);
  2282. }
  2283. parse_events_error__exit(&err);
  2284. evlist__delete(evlist);
  2285. return ret;
  2286. }
  2287. static int test_event_fake_pmu(const char *str)
  2288. {
  2289. struct parse_events_error err;
  2290. struct evlist *evlist;
  2291. int ret;
  2292. evlist = evlist__new();
  2293. if (!evlist)
  2294. return -ENOMEM;
  2295. parse_events_error__init(&err);
  2296. ret = __parse_events(evlist, str, /*pmu_filter=*/NULL, &err,
  2297. /*fake_pmu=*/true, /*warn_if_reordered=*/true,
  2298. /*fake_tp=*/true);
  2299. if (ret) {
  2300. pr_debug("failed to parse event '%s', err %d\n",
  2301. str, ret);
  2302. parse_events_error__print(&err, str);
  2303. }
  2304. parse_events_error__exit(&err);
  2305. evlist__delete(evlist);
  2306. return ret;
  2307. }
  2308. static int combine_test_results(int existing, int latest)
  2309. {
  2310. if (existing == TEST_FAIL)
  2311. return TEST_FAIL;
  2312. if (existing == TEST_SKIP)
  2313. return latest == TEST_OK ? TEST_SKIP : latest;
  2314. return latest;
  2315. }
  2316. static int test_events(const struct evlist_test *events, int cnt)
  2317. {
  2318. int ret = TEST_OK;
  2319. struct perf_pmu *core_pmu = perf_pmus__find_core_pmu();
  2320. for (int i = 0; i < cnt; i++) {
  2321. struct evlist_test e = events[i];
  2322. int test_ret;
  2323. const char *pos = e.name, *end;
  2324. char buf[1024], *buf_pos = buf;
  2325. while ((end = strstr(pos, "default_core"))) {
  2326. size_t len = end - pos;
  2327. strncpy(buf_pos, pos, len);
  2328. pos = end + 12;
  2329. buf_pos += len;
  2330. strcpy(buf_pos, core_pmu->name);
  2331. buf_pos += strlen(core_pmu->name);
  2332. }
  2333. strcpy(buf_pos, pos);
  2334. e.name = buf;
  2335. pr_debug("running test %d '%s'\n", i, e.name);
  2336. test_ret = test_event(&e);
  2337. if (test_ret != TEST_OK) {
  2338. pr_debug("Event test failure: test %d '%s'\n", i, e.name);
  2339. ret = combine_test_results(ret, test_ret);
  2340. }
  2341. }
  2342. return ret;
  2343. }
  2344. static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  2345. {
  2346. return test_events(test__events, ARRAY_SIZE(test__events));
  2347. }
  2348. static int test_term(const struct terms_test *t)
  2349. {
  2350. struct parse_events_terms terms;
  2351. int ret;
  2352. parse_events_terms__init(&terms);
  2353. ret = parse_events_terms(&terms, t->str);
  2354. if (ret) {
  2355. pr_debug("failed to parse terms '%s', err %d\n",
  2356. t->str , ret);
  2357. return ret;
  2358. }
  2359. ret = t->check(&terms);
  2360. parse_events_terms__exit(&terms);
  2361. return ret;
  2362. }
  2363. static int test_terms(const struct terms_test *terms, int cnt)
  2364. {
  2365. int ret = 0;
  2366. for (int i = 0; i < cnt; i++) {
  2367. const struct terms_test *t = &terms[i];
  2368. pr_debug("running test %d '%s'\n", i, t->str);
  2369. ret = test_term(t);
  2370. if (ret)
  2371. break;
  2372. }
  2373. return ret;
  2374. }
  2375. static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  2376. {
  2377. return test_terms(test__terms, ARRAY_SIZE(test__terms));
  2378. }
  2379. static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  2380. {
  2381. struct perf_pmu *pmu = NULL;
  2382. int ret = TEST_OK;
  2383. while ((pmu = perf_pmus__scan(pmu)) != NULL) {
  2384. struct stat st;
  2385. char path[PATH_MAX];
  2386. char pmu_event[PATH_MAX];
  2387. char *buf = NULL;
  2388. FILE *file;
  2389. struct dirent *ent;
  2390. size_t len = 0;
  2391. DIR *dir;
  2392. int err;
  2393. int n;
  2394. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
  2395. sysfs__mountpoint(), pmu->name);
  2396. err = stat(path, &st);
  2397. if (err) {
  2398. pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);
  2399. continue;
  2400. }
  2401. dir = opendir(path);
  2402. if (!dir) {
  2403. pr_debug("can't open pmu event dir: %s\n", path);
  2404. ret = combine_test_results(ret, TEST_SKIP);
  2405. continue;
  2406. }
  2407. while ((ent = readdir(dir))) {
  2408. struct evlist_test e = { .name = NULL, };
  2409. char name[2 * NAME_MAX + 1 + 12 + 3];
  2410. int test_ret;
  2411. bool is_event_parameterized = 0;
  2412. /* Names containing . are special and cannot be used directly */
  2413. if (strchr(ent->d_name, '.'))
  2414. continue;
  2415. /* exclude parameterized ones (name contains '?') */
  2416. n = snprintf(pmu_event, sizeof(pmu_event), "%s%s", path, ent->d_name);
  2417. if (n >= PATH_MAX) {
  2418. pr_err("pmu event name crossed PATH_MAX(%d) size\n", PATH_MAX);
  2419. continue;
  2420. }
  2421. file = fopen(pmu_event, "r");
  2422. if (!file) {
  2423. pr_debug("can't open pmu event file for '%s'\n", ent->d_name);
  2424. ret = combine_test_results(ret, TEST_FAIL);
  2425. continue;
  2426. }
  2427. if (getline(&buf, &len, file) < 0) {
  2428. pr_debug(" pmu event: %s is a null event\n", ent->d_name);
  2429. ret = combine_test_results(ret, TEST_FAIL);
  2430. fclose(file);
  2431. continue;
  2432. }
  2433. if (strchr(buf, '?'))
  2434. is_event_parameterized = 1;
  2435. free(buf);
  2436. buf = NULL;
  2437. fclose(file);
  2438. if (is_event_parameterized == 1) {
  2439. pr_debug("skipping parameterized PMU event: %s which contains ?\n", pmu_event);
  2440. continue;
  2441. }
  2442. snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
  2443. e.name = name;
  2444. e.check = test__checkevent_pmu_events;
  2445. test_ret = test_event(&e);
  2446. if (test_ret != TEST_OK) {
  2447. pr_debug("Test PMU event failed for '%s'\n", name);
  2448. ret = combine_test_results(ret, test_ret);
  2449. }
  2450. if (!is_pmu_core(pmu->name))
  2451. continue;
  2452. /*
  2453. * Names containing '-' are recognized as prefixes and suffixes
  2454. * due to '-' being a legacy PMU separator. This fails when the
  2455. * prefix or suffix collides with an existing legacy token. For
  2456. * example, branch-brs has a prefix (branch) that collides with
  2457. * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix
  2458. * isn't expected after this. As event names in the config
  2459. * slashes are allowed a '-' in the name we check this works
  2460. * above.
  2461. */
  2462. if (strchr(ent->d_name, '-'))
  2463. continue;
  2464. snprintf(name, sizeof(name), "%s:u,%s/event=%s/u",
  2465. ent->d_name, pmu->name, ent->d_name);
  2466. e.name = name;
  2467. e.check = test__checkevent_pmu_events_mix;
  2468. test_ret = test_event(&e);
  2469. if (test_ret != TEST_OK) {
  2470. pr_debug("Test PMU event failed for '%s'\n", name);
  2471. ret = combine_test_results(ret, test_ret);
  2472. }
  2473. }
  2474. closedir(dir);
  2475. }
  2476. return ret;
  2477. }
  2478. static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  2479. {
  2480. return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
  2481. }
  2482. static bool test_alias(char **event, char **alias)
  2483. {
  2484. char path[PATH_MAX];
  2485. DIR *dir;
  2486. struct dirent *dent;
  2487. const char *sysfs = sysfs__mountpoint();
  2488. char buf[128];
  2489. FILE *file;
  2490. if (!sysfs)
  2491. return false;
  2492. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs);
  2493. dir = opendir(path);
  2494. if (!dir)
  2495. return false;
  2496. while ((dent = readdir(dir))) {
  2497. if (!strcmp(dent->d_name, ".") ||
  2498. !strcmp(dent->d_name, ".."))
  2499. continue;
  2500. snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias",
  2501. sysfs, dent->d_name);
  2502. if (!file_available(path))
  2503. continue;
  2504. file = fopen(path, "r");
  2505. if (!file)
  2506. continue;
  2507. if (!fgets(buf, sizeof(buf), file)) {
  2508. fclose(file);
  2509. continue;
  2510. }
  2511. /* Remove the last '\n' */
  2512. buf[strlen(buf) - 1] = 0;
  2513. fclose(file);
  2514. *event = strdup(dent->d_name);
  2515. *alias = strdup(buf);
  2516. closedir(dir);
  2517. if (*event == NULL || *alias == NULL) {
  2518. free(*event);
  2519. free(*alias);
  2520. return false;
  2521. }
  2522. return true;
  2523. }
  2524. closedir(dir);
  2525. return false;
  2526. }
  2527. static int test__checkevent_pmu_events_alias(struct evlist *evlist)
  2528. {
  2529. struct evsel *evsel1 = evlist__first(evlist);
  2530. struct evsel *evsel2 = evlist__last(evlist);
  2531. TEST_ASSERT_EVSEL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type, evsel1);
  2532. TEST_ASSERT_EVSEL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config,
  2533. evsel1);
  2534. return TEST_OK;
  2535. }
  2536. static int test__pmu_events_alias(char *event, char *alias)
  2537. {
  2538. struct evlist_test e = { .name = NULL, };
  2539. char name[2 * NAME_MAX + 20];
  2540. snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/",
  2541. event, alias);
  2542. e.name = name;
  2543. e.check = test__checkevent_pmu_events_alias;
  2544. return test_event(&e);
  2545. }
  2546. static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  2547. {
  2548. char *event, *alias;
  2549. int ret;
  2550. if (!test_alias(&event, &alias))
  2551. return TEST_SKIP;
  2552. ret = test__pmu_events_alias(event, alias);
  2553. free(event);
  2554. free(alias);
  2555. return ret;
  2556. }
  2557. static int test__pmu_events_alias2(struct test_suite *test __maybe_unused,
  2558. int subtest __maybe_unused)
  2559. {
  2560. static const char events[][30] = {
  2561. "event-hyphen",
  2562. "event-two-hyph",
  2563. };
  2564. int ret = TEST_OK;
  2565. for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) {
  2566. int test_ret = test_event_fake_pmu(&events[i][0]);
  2567. if (test_ret != TEST_OK) {
  2568. pr_debug("check_parse_fake %s failed\n", &events[i][0]);
  2569. ret = combine_test_results(ret, test_ret);
  2570. }
  2571. }
  2572. return ret;
  2573. }
  2574. static struct test_case tests__parse_events[] = {
  2575. TEST_CASE_REASON("Test event parsing",
  2576. events2,
  2577. "permissions"),
  2578. TEST_CASE_REASON("Parsing of all PMU events from sysfs",
  2579. pmu_events,
  2580. "permissions"),
  2581. TEST_CASE_REASON("Parsing of given PMU events from sysfs",
  2582. pmu_events2,
  2583. "permissions"),
  2584. TEST_CASE_REASON("Parsing of aliased events from sysfs", alias,
  2585. "no aliases in sysfs"),
  2586. TEST_CASE("Parsing of aliased events", pmu_events_alias2),
  2587. TEST_CASE("Parsing of terms (event modifiers)", terms2),
  2588. { .name = NULL, }
  2589. };
  2590. struct test_suite suite__parse_events = {
  2591. .desc = "Parse event definition strings",
  2592. .test_cases = tests__parse_events,
  2593. };