parse-events.c 90 KB

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