1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2945aea22SJiri Olsa #include "parse-events.h"
3945aea22SJiri Olsa #include "evsel.h"
4945aea22SJiri Olsa #include "evlist.h"
5cd0cfad7SBorislav Petkov #include <api/fs/fs.h>
6c81251e8SJiri Olsa #include "tests.h"
784f5d36fSJiri Olsa #include "debug.h"
8f2a39fe8SArnaldo Carvalho de Melo #include "pmu.h"
95a52817eSIan Rogers #include "pmus.h"
1076b31a29SArnaldo Carvalho de Melo #include <dirent.h>
11a43783aeSArnaldo Carvalho de Melo #include <errno.h>
12c7a3828dSJin Yao #include "fncache.h"
137a8ef4c4SArnaldo Carvalho de Melo #include <sys/types.h>
147a8ef4c4SArnaldo Carvalho de Melo #include <sys/stat.h>
157a8ef4c4SArnaldo Carvalho de Melo #include <unistd.h>
16877a7a11SArnaldo Carvalho de Melo #include <linux/kernel.h>
17f0b9abfbSIngo Molnar #include <linux/hw_breakpoint.h>
1820a9ed28SArnaldo Carvalho de Melo #include <api/fs/tracing_path.h>
19945aea22SJiri Olsa
20945aea22SJiri Olsa #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
21945aea22SJiri Olsa PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
22945aea22SJiri Olsa
num_core_entries(void)23bcd981dbSJames Clark static int num_core_entries(void)
24bcd981dbSJames Clark {
25bcd981dbSJames Clark /*
26bcd981dbSJames Clark * If the kernel supports extended type, expect events to be
27bcd981dbSJames Clark * opened once for each core PMU type. Otherwise fall back to the legacy
28bcd981dbSJames Clark * behavior of opening only one event even though there are multiple
29bcd981dbSJames Clark * PMUs
30bcd981dbSJames Clark */
31bcd981dbSJames Clark if (perf_pmus__supports_extended_type())
32bcd981dbSJames Clark return perf_pmus__num_core_pmus();
33bcd981dbSJames Clark
34bcd981dbSJames Clark return 1;
35bcd981dbSJames Clark }
36bcd981dbSJames Clark
test_config(const struct evsel * evsel,__u64 expected_config)379854934bSIan Rogers static bool test_config(const struct evsel *evsel, __u64 expected_config)
389854934bSIan Rogers {
399854934bSIan Rogers __u32 type = evsel->core.attr.type;
409854934bSIan Rogers __u64 config = evsel->core.attr.config;
419854934bSIan Rogers
429854934bSIan Rogers if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) {
439854934bSIan Rogers /*
449854934bSIan Rogers * HARDWARE and HW_CACHE events encode the PMU's extended type
459854934bSIan Rogers * in the top 32-bits. Mask in order to ignore.
469854934bSIan Rogers */
479854934bSIan Rogers config &= PERF_HW_EVENT_MASK;
489854934bSIan Rogers }
499854934bSIan Rogers return config == expected_config;
509854934bSIan Rogers }
519854934bSIan Rogers
test_perf_config(const struct perf_evsel * evsel,__u64 expected_config)52aefde50aSIan Rogers static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_config)
53aefde50aSIan Rogers {
54aefde50aSIan Rogers return (evsel->attr.config & PERF_HW_EVENT_MASK) == expected_config;
55aefde50aSIan Rogers }
56aefde50aSIan Rogers
57378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
58378ef0f5SIan Rogers
5953fe307dSThomas Richter #if defined(__s390x__)
6053fe307dSThomas Richter /* Return true if kvm module is available and loaded. Test this
614d39c89fSIngo Molnar * and return success when trace point kvm_s390_create_vm
6253fe307dSThomas Richter * exists. Otherwise this test always fails.
6353fe307dSThomas Richter */
kvm_s390_create_vm_valid(void)6453fe307dSThomas Richter static bool kvm_s390_create_vm_valid(void)
6553fe307dSThomas Richter {
6653fe307dSThomas Richter char *eventfile;
6753fe307dSThomas Richter bool rc = false;
6853fe307dSThomas Richter
6953fe307dSThomas Richter eventfile = get_events_file("kvm-s390");
7053fe307dSThomas Richter
7153fe307dSThomas Richter if (eventfile) {
7253fe307dSThomas Richter DIR *mydir = opendir(eventfile);
7353fe307dSThomas Richter
7453fe307dSThomas Richter if (mydir) {
7553fe307dSThomas Richter rc = true;
7653fe307dSThomas Richter closedir(mydir);
7753fe307dSThomas Richter }
7853fe307dSThomas Richter put_events_file(eventfile);
7953fe307dSThomas Richter }
8053fe307dSThomas Richter
8153fe307dSThomas Richter return rc;
8253fe307dSThomas Richter }
8353fe307dSThomas Richter #endif
8453fe307dSThomas Richter
test__checkevent_tracepoint(struct evlist * evlist)8563503dbaSJiri Olsa static int test__checkevent_tracepoint(struct evlist *evlist)
86945aea22SJiri Olsa {
87515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
88945aea22SJiri Olsa
896484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
909d2dc632SIan Rogers TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
911fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
92945aea22SJiri Olsa TEST_ASSERT_VAL("wrong sample_type",
931fc632ceSJiri Olsa PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
941fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
957741e03eSIan Rogers return TEST_OK;
96945aea22SJiri Olsa }
97945aea22SJiri Olsa
test__checkevent_tracepoint_multi(struct evlist * evlist)9863503dbaSJiri Olsa static int test__checkevent_tracepoint_multi(struct evlist *evlist)
99945aea22SJiri Olsa {
10032dcd021SJiri Olsa struct evsel *evsel;
101945aea22SJiri Olsa
1026484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
1039d2dc632SIan Rogers TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
104945aea22SJiri Olsa
105e5cadb93SArnaldo Carvalho de Melo evlist__for_each_entry(evlist, evsel) {
106945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type",
1071fc632ceSJiri Olsa PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
108945aea22SJiri Olsa TEST_ASSERT_VAL("wrong sample_type",
1091fc632ceSJiri Olsa PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
110945aea22SJiri Olsa TEST_ASSERT_VAL("wrong sample_period",
1111fc632ceSJiri Olsa 1 == evsel->core.attr.sample_period);
112945aea22SJiri Olsa }
1137741e03eSIan Rogers return TEST_OK;
114945aea22SJiri Olsa }
115378ef0f5SIan Rogers #endif /* HAVE_LIBTRACEEVENT */
116945aea22SJiri Olsa
test__checkevent_raw(struct evlist * evlist)11763503dbaSJiri Olsa static int test__checkevent_raw(struct evlist *evlist)
118945aea22SJiri Olsa {
119aefde50aSIan Rogers struct perf_evsel *evsel;
120aefde50aSIan Rogers bool raw_type_match = false;
121945aea22SJiri Olsa
122aefde50aSIan Rogers TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
123aefde50aSIan Rogers
124aefde50aSIan Rogers perf_evlist__for_each_evsel(&evlist->core, evsel) {
125808ce56eSJames Clark struct perf_pmu *pmu __maybe_unused = NULL;
126aefde50aSIan Rogers bool type_matched = false;
127aefde50aSIan Rogers
128aefde50aSIan Rogers TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a));
129808ce56eSJames Clark TEST_ASSERT_VAL("event not parsed as raw type",
130808ce56eSJames Clark evsel->attr.type == PERF_TYPE_RAW);
131808ce56eSJames Clark #if defined(__aarch64__)
132808ce56eSJames Clark /*
133808ce56eSJames Clark * Arm doesn't have a real raw type PMU in sysfs, so raw events
134808ce56eSJames Clark * would never match any PMU. However, RAW events on Arm will
135808ce56eSJames Clark * always successfully open on the first available core PMU
136808ce56eSJames Clark * so no need to test for a matching type here.
137808ce56eSJames Clark */
138808ce56eSJames Clark type_matched = raw_type_match = true;
139808ce56eSJames Clark #else
1401eaf496eSIan Rogers while ((pmu = perf_pmus__scan(pmu)) != NULL) {
141aefde50aSIan Rogers if (pmu->type == evsel->attr.type) {
142aefde50aSIan Rogers TEST_ASSERT_VAL("PMU type expected once", !type_matched);
143aefde50aSIan Rogers type_matched = true;
144aefde50aSIan Rogers if (pmu->type == PERF_TYPE_RAW)
145aefde50aSIan Rogers raw_type_match = true;
146aefde50aSIan Rogers }
147aefde50aSIan Rogers }
148808ce56eSJames Clark #endif
149aefde50aSIan Rogers TEST_ASSERT_VAL("No PMU found for type", type_matched);
150aefde50aSIan Rogers }
151aefde50aSIan Rogers TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match);
1527741e03eSIan Rogers return TEST_OK;
153945aea22SJiri Olsa }
154945aea22SJiri Olsa
test__checkevent_numeric(struct evlist * evlist)15563503dbaSJiri Olsa static int test__checkevent_numeric(struct evlist *evlist)
156945aea22SJiri Olsa {
157515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
158945aea22SJiri Olsa
1596484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1601fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
1619854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
1627741e03eSIan Rogers return TEST_OK;
163945aea22SJiri Olsa }
164945aea22SJiri Olsa
test__checkevent_symbolic_name(struct evlist * evlist)16563503dbaSJiri Olsa static int test__checkevent_symbolic_name(struct evlist *evlist)
166945aea22SJiri Olsa {
167aefde50aSIan Rogers struct perf_evsel *evsel;
168945aea22SJiri Olsa
169aefde50aSIan Rogers TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
170aefde50aSIan Rogers
171aefde50aSIan Rogers perf_evlist__for_each_evsel(&evlist->core, evsel) {
172aefde50aSIan Rogers TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
173aefde50aSIan Rogers TEST_ASSERT_VAL("wrong config",
174aefde50aSIan Rogers test_perf_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
175aefde50aSIan Rogers }
1767741e03eSIan Rogers return TEST_OK;
177945aea22SJiri Olsa }
178945aea22SJiri Olsa
test__checkevent_symbolic_name_config(struct evlist * evlist)17963503dbaSJiri Olsa static int test__checkevent_symbolic_name_config(struct evlist *evlist)
180945aea22SJiri Olsa {
181aefde50aSIan Rogers struct perf_evsel *evsel;
182945aea22SJiri Olsa
183aefde50aSIan Rogers TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
184aefde50aSIan Rogers
185aefde50aSIan Rogers perf_evlist__for_each_evsel(&evlist->core, evsel) {
186aefde50aSIan Rogers TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
187aefde50aSIan Rogers TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
188ee4c7588SJiri Olsa /*
18978e1bc25SArnaldo Carvalho de Melo * The period value gets configured within evlist__config,
190ee4c7588SJiri Olsa * while this test executes only parse events method.
191ee4c7588SJiri Olsa */
192aefde50aSIan Rogers TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
193aefde50aSIan Rogers TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
194aefde50aSIan Rogers TEST_ASSERT_VAL("wrong config2", 1 == evsel->attr.config2);
195aefde50aSIan Rogers }
1967741e03eSIan Rogers return TEST_OK;
197945aea22SJiri Olsa }
198945aea22SJiri Olsa
test__checkevent_symbolic_alias(struct evlist * evlist)19963503dbaSJiri Olsa static int test__checkevent_symbolic_alias(struct evlist *evlist)
200945aea22SJiri Olsa {
201515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
202945aea22SJiri Olsa
2036484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
2041fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
2059854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
2067741e03eSIan Rogers return TEST_OK;
207945aea22SJiri Olsa }
208945aea22SJiri Olsa
test__checkevent_genhw(struct evlist * evlist)20963503dbaSJiri Olsa static int test__checkevent_genhw(struct evlist *evlist)
210945aea22SJiri Olsa {
211aefde50aSIan Rogers struct perf_evsel *evsel;
212945aea22SJiri Olsa
213aefde50aSIan Rogers TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
214aefde50aSIan Rogers
215aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
216aefde50aSIan Rogers TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
217aefde50aSIan Rogers TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 1 << 16));
218aefde50aSIan Rogers }
2197741e03eSIan Rogers return TEST_OK;
220945aea22SJiri Olsa }
221945aea22SJiri Olsa
test__checkevent_breakpoint(struct evlist * evlist)22263503dbaSJiri Olsa static int test__checkevent_breakpoint(struct evlist *evlist)
223945aea22SJiri Olsa {
224515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
225945aea22SJiri Olsa
2266484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
2271fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
2289854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
229945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
2301fc632ceSJiri Olsa evsel->core.attr.bp_type);
231945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
2321fc632ceSJiri Olsa evsel->core.attr.bp_len);
2337741e03eSIan Rogers return TEST_OK;
234945aea22SJiri Olsa }
235945aea22SJiri Olsa
test__checkevent_breakpoint_x(struct evlist * evlist)23663503dbaSJiri Olsa static int test__checkevent_breakpoint_x(struct evlist *evlist)
237945aea22SJiri Olsa {
238515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
239945aea22SJiri Olsa
2406484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
2411fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
2429854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
243945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_type",
2441fc632ceSJiri Olsa HW_BREAKPOINT_X == evsel->core.attr.bp_type);
2451fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
2467741e03eSIan Rogers return TEST_OK;
247945aea22SJiri Olsa }
248945aea22SJiri Olsa
test__checkevent_breakpoint_r(struct evlist * evlist)24963503dbaSJiri Olsa static int test__checkevent_breakpoint_r(struct evlist *evlist)
250945aea22SJiri Olsa {
251515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
252945aea22SJiri Olsa
2536484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
254945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type",
2551fc632ceSJiri Olsa PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
2569854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
257945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_type",
2581fc632ceSJiri Olsa HW_BREAKPOINT_R == evsel->core.attr.bp_type);
259945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_len",
2601fc632ceSJiri Olsa HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
2617741e03eSIan Rogers return TEST_OK;
262945aea22SJiri Olsa }
263945aea22SJiri Olsa
test__checkevent_breakpoint_w(struct evlist * evlist)26463503dbaSJiri Olsa static int test__checkevent_breakpoint_w(struct evlist *evlist)
265945aea22SJiri Olsa {
266515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
267945aea22SJiri Olsa
2686484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
269945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type",
2701fc632ceSJiri Olsa PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
2719854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
272945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_type",
2731fc632ceSJiri Olsa HW_BREAKPOINT_W == evsel->core.attr.bp_type);
274945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_len",
2751fc632ceSJiri Olsa HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
2767741e03eSIan Rogers return TEST_OK;
277945aea22SJiri Olsa }
278945aea22SJiri Olsa
test__checkevent_breakpoint_rw(struct evlist * evlist)27963503dbaSJiri Olsa static int test__checkevent_breakpoint_rw(struct evlist *evlist)
280945aea22SJiri Olsa {
281515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
282945aea22SJiri Olsa
2836484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
284945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type",
2851fc632ceSJiri Olsa PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
2869854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
287945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_type",
2881fc632ceSJiri Olsa (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
289945aea22SJiri Olsa TEST_ASSERT_VAL("wrong bp_len",
2901fc632ceSJiri Olsa HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
2917741e03eSIan Rogers return TEST_OK;
292945aea22SJiri Olsa }
293945aea22SJiri Olsa
294378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
test__checkevent_tracepoint_modifier(struct evlist * evlist)29563503dbaSJiri Olsa static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
296945aea22SJiri Olsa {
297515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
298945aea22SJiri Olsa
2991fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
3001fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
3011fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
3021fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
303945aea22SJiri Olsa
304945aea22SJiri Olsa return test__checkevent_tracepoint(evlist);
305945aea22SJiri Olsa }
306945aea22SJiri Olsa
307945aea22SJiri Olsa static int
test__checkevent_tracepoint_multi_modifier(struct evlist * evlist)30863503dbaSJiri Olsa test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
309945aea22SJiri Olsa {
310aefde50aSIan Rogers struct perf_evsel *evsel;
311945aea22SJiri Olsa
3126484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
313945aea22SJiri Olsa
314aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
315aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
316aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
317aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
318aefde50aSIan Rogers TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
319945aea22SJiri Olsa }
320945aea22SJiri Olsa
321945aea22SJiri Olsa return test__checkevent_tracepoint_multi(evlist);
322945aea22SJiri Olsa }
323378ef0f5SIan Rogers #endif /* HAVE_LIBTRACEEVENT */
324945aea22SJiri Olsa
test__checkevent_raw_modifier(struct evlist * evlist)32563503dbaSJiri Olsa static int test__checkevent_raw_modifier(struct evlist *evlist)
326945aea22SJiri Olsa {
327aefde50aSIan Rogers struct perf_evsel *evsel;
328945aea22SJiri Olsa
329aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
330aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
331aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
332aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
333aefde50aSIan Rogers TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
334aefde50aSIan Rogers }
335945aea22SJiri Olsa return test__checkevent_raw(evlist);
336945aea22SJiri Olsa }
337945aea22SJiri Olsa
test__checkevent_numeric_modifier(struct evlist * evlist)33863503dbaSJiri Olsa static int test__checkevent_numeric_modifier(struct evlist *evlist)
339945aea22SJiri Olsa {
340aefde50aSIan Rogers struct perf_evsel *evsel;
341945aea22SJiri Olsa
342aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
343aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
344aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
345aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
346aefde50aSIan Rogers TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
347aefde50aSIan Rogers }
348945aea22SJiri Olsa return test__checkevent_numeric(evlist);
349945aea22SJiri Olsa }
350945aea22SJiri Olsa
test__checkevent_symbolic_name_modifier(struct evlist * evlist)35163503dbaSJiri Olsa static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
352945aea22SJiri Olsa {
35327c9fcfcSIan Rogers struct perf_evsel *evsel;
354945aea22SJiri Olsa
35527c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
356bcd981dbSJames Clark evlist->core.nr_entries == num_core_entries());
357945aea22SJiri Olsa
35827c9fcfcSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
35927c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
36027c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
36127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
36227c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
36327c9fcfcSIan Rogers }
364945aea22SJiri Olsa return test__checkevent_symbolic_name(evlist);
365945aea22SJiri Olsa }
366945aea22SJiri Olsa
test__checkevent_exclude_host_modifier(struct evlist * evlist)36763503dbaSJiri Olsa static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
368945aea22SJiri Olsa {
369aefde50aSIan Rogers struct perf_evsel *evsel;
370945aea22SJiri Olsa
371aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
372aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
373aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
374aefde50aSIan Rogers }
375945aea22SJiri Olsa return test__checkevent_symbolic_name(evlist);
376945aea22SJiri Olsa }
377945aea22SJiri Olsa
test__checkevent_exclude_guest_modifier(struct evlist * evlist)37863503dbaSJiri Olsa static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
379945aea22SJiri Olsa {
380aefde50aSIan Rogers struct perf_evsel *evsel;
381945aea22SJiri Olsa
382aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
383aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
384aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
385aefde50aSIan Rogers }
386945aea22SJiri Olsa return test__checkevent_symbolic_name(evlist);
387945aea22SJiri Olsa }
388945aea22SJiri Olsa
test__checkevent_symbolic_alias_modifier(struct evlist * evlist)38963503dbaSJiri Olsa static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
390945aea22SJiri Olsa {
391515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
392945aea22SJiri Olsa
3931fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
3941fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
3951fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
3961fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
397945aea22SJiri Olsa
398945aea22SJiri Olsa return test__checkevent_symbolic_alias(evlist);
399945aea22SJiri Olsa }
400945aea22SJiri Olsa
test__checkevent_genhw_modifier(struct evlist * evlist)40163503dbaSJiri Olsa static int test__checkevent_genhw_modifier(struct evlist *evlist)
402945aea22SJiri Olsa {
403aefde50aSIan Rogers struct perf_evsel *evsel;
404945aea22SJiri Olsa
405aefde50aSIan Rogers perf_evlist__for_each_entry(&evlist->core, evsel) {
406aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
407aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
408aefde50aSIan Rogers TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
409aefde50aSIan Rogers TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
410aefde50aSIan Rogers }
411945aea22SJiri Olsa return test__checkevent_genhw(evlist);
412945aea22SJiri Olsa }
413945aea22SJiri Olsa
test__checkevent_exclude_idle_modifier(struct evlist * evlist)41463503dbaSJiri Olsa static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
415a1e12da4SJiri Olsa {
416515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
417a1e12da4SJiri Olsa
4181fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
4191fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
4201fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
4211fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
4221fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
4231fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
4241fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
425a1e12da4SJiri Olsa
426a1e12da4SJiri Olsa return test__checkevent_symbolic_name(evlist);
427a1e12da4SJiri Olsa }
428a1e12da4SJiri Olsa
test__checkevent_exclude_idle_modifier_1(struct evlist * evlist)42963503dbaSJiri Olsa static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
430a1e12da4SJiri Olsa {
431515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
432a1e12da4SJiri Olsa
4331fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
4341fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
4351fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
4361fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
4371fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
4381fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
4391fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
440a1e12da4SJiri Olsa
441a1e12da4SJiri Olsa return test__checkevent_symbolic_name(evlist);
442a1e12da4SJiri Olsa }
443a1e12da4SJiri Olsa
test__checkevent_breakpoint_modifier(struct evlist * evlist)44463503dbaSJiri Olsa static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
445945aea22SJiri Olsa {
446515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
447945aea22SJiri Olsa
448945aea22SJiri Olsa
4491fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
4501fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
4511fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
4521fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
453945aea22SJiri Olsa TEST_ASSERT_VAL("wrong name",
4548ab2e96dSArnaldo Carvalho de Melo !strcmp(evsel__name(evsel), "mem:0:u"));
455945aea22SJiri Olsa
456945aea22SJiri Olsa return test__checkevent_breakpoint(evlist);
457945aea22SJiri Olsa }
458945aea22SJiri Olsa
test__checkevent_breakpoint_x_modifier(struct evlist * evlist)45963503dbaSJiri Olsa static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
460945aea22SJiri Olsa {
461515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
462945aea22SJiri Olsa
4631fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
4641fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
4651fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
4661fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
467945aea22SJiri Olsa TEST_ASSERT_VAL("wrong name",
4688ab2e96dSArnaldo Carvalho de Melo !strcmp(evsel__name(evsel), "mem:0:x:k"));
469945aea22SJiri Olsa
470945aea22SJiri Olsa return test__checkevent_breakpoint_x(evlist);
471945aea22SJiri Olsa }
472945aea22SJiri Olsa
test__checkevent_breakpoint_r_modifier(struct evlist * evlist)47363503dbaSJiri Olsa static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
474945aea22SJiri Olsa {
475515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
476945aea22SJiri Olsa
4771fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
4781fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
4791fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
4801fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
481945aea22SJiri Olsa TEST_ASSERT_VAL("wrong name",
4828ab2e96dSArnaldo Carvalho de Melo !strcmp(evsel__name(evsel), "mem:0:r:hp"));
483945aea22SJiri Olsa
484945aea22SJiri Olsa return test__checkevent_breakpoint_r(evlist);
485945aea22SJiri Olsa }
486945aea22SJiri Olsa
test__checkevent_breakpoint_w_modifier(struct evlist * evlist)48763503dbaSJiri Olsa static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
488945aea22SJiri Olsa {
489515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
490945aea22SJiri Olsa
4911fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
4921fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
4931fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
4941fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
495945aea22SJiri Olsa TEST_ASSERT_VAL("wrong name",
4968ab2e96dSArnaldo Carvalho de Melo !strcmp(evsel__name(evsel), "mem:0:w:up"));
497945aea22SJiri Olsa
498945aea22SJiri Olsa return test__checkevent_breakpoint_w(evlist);
499945aea22SJiri Olsa }
500945aea22SJiri Olsa
test__checkevent_breakpoint_rw_modifier(struct evlist * evlist)50163503dbaSJiri Olsa static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
502945aea22SJiri Olsa {
503515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
504945aea22SJiri Olsa
5051fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
5061fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
5071fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
5081fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
509945aea22SJiri Olsa TEST_ASSERT_VAL("wrong name",
5108ab2e96dSArnaldo Carvalho de Melo !strcmp(evsel__name(evsel), "mem:0:rw:kp"));
511945aea22SJiri Olsa
512945aea22SJiri Olsa return test__checkevent_breakpoint_rw(evlist);
513945aea22SJiri Olsa }
514945aea22SJiri Olsa
test__checkevent_breakpoint_modifier_name(struct evlist * evlist)515f0617f52SAdrian Hunter static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist)
516f0617f52SAdrian Hunter {
517f0617f52SAdrian Hunter struct evsel *evsel = evlist__first(evlist);
518f0617f52SAdrian Hunter
519f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
520f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
521f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
522f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
523f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name",
524f0617f52SAdrian Hunter !strcmp(evsel__name(evsel), "breakpoint"));
525f0617f52SAdrian Hunter
526f0617f52SAdrian Hunter return test__checkevent_breakpoint(evlist);
527f0617f52SAdrian Hunter }
528f0617f52SAdrian Hunter
test__checkevent_breakpoint_x_modifier_name(struct evlist * evlist)529f0617f52SAdrian Hunter static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist)
530f0617f52SAdrian Hunter {
531f0617f52SAdrian Hunter struct evsel *evsel = evlist__first(evlist);
532f0617f52SAdrian Hunter
533f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
534f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
535f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
536f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
537f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name",
538f0617f52SAdrian Hunter !strcmp(evsel__name(evsel), "breakpoint"));
539f0617f52SAdrian Hunter
540f0617f52SAdrian Hunter return test__checkevent_breakpoint_x(evlist);
541f0617f52SAdrian Hunter }
542f0617f52SAdrian Hunter
test__checkevent_breakpoint_r_modifier_name(struct evlist * evlist)543f0617f52SAdrian Hunter static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist)
544f0617f52SAdrian Hunter {
545f0617f52SAdrian Hunter struct evsel *evsel = evlist__first(evlist);
546f0617f52SAdrian Hunter
547f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
548f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
549f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
550f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
551f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name",
552f0617f52SAdrian Hunter !strcmp(evsel__name(evsel), "breakpoint"));
553f0617f52SAdrian Hunter
554f0617f52SAdrian Hunter return test__checkevent_breakpoint_r(evlist);
555f0617f52SAdrian Hunter }
556f0617f52SAdrian Hunter
test__checkevent_breakpoint_w_modifier_name(struct evlist * evlist)557f0617f52SAdrian Hunter static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist)
558f0617f52SAdrian Hunter {
559f0617f52SAdrian Hunter struct evsel *evsel = evlist__first(evlist);
560f0617f52SAdrian Hunter
561f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
562f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
563f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
564f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
565f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name",
566f0617f52SAdrian Hunter !strcmp(evsel__name(evsel), "breakpoint"));
567f0617f52SAdrian Hunter
568f0617f52SAdrian Hunter return test__checkevent_breakpoint_w(evlist);
569f0617f52SAdrian Hunter }
570f0617f52SAdrian Hunter
test__checkevent_breakpoint_rw_modifier_name(struct evlist * evlist)571f0617f52SAdrian Hunter static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist)
572f0617f52SAdrian Hunter {
573f0617f52SAdrian Hunter struct evsel *evsel = evlist__first(evlist);
574f0617f52SAdrian Hunter
575f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
576f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
577f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
578f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
579f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name",
580f0617f52SAdrian Hunter !strcmp(evsel__name(evsel), "breakpoint"));
581f0617f52SAdrian Hunter
582f0617f52SAdrian Hunter return test__checkevent_breakpoint_rw(evlist);
583f0617f52SAdrian Hunter }
584f0617f52SAdrian Hunter
test__checkevent_breakpoint_2_events(struct evlist * evlist)585f0617f52SAdrian Hunter static int test__checkevent_breakpoint_2_events(struct evlist *evlist)
586f0617f52SAdrian Hunter {
587f0617f52SAdrian Hunter struct evsel *evsel = evlist__first(evlist);
588f0617f52SAdrian Hunter
589f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
590f0617f52SAdrian Hunter
591f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
592f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint1"));
593f0617f52SAdrian Hunter
594f0617f52SAdrian Hunter evsel = evsel__next(evsel);
595f0617f52SAdrian Hunter
596f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
597f0617f52SAdrian Hunter TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint2"));
598f0617f52SAdrian Hunter
599f0617f52SAdrian Hunter return TEST_OK;
600f0617f52SAdrian Hunter }
601f0617f52SAdrian Hunter
test__checkevent_pmu(struct evlist * evlist)60263503dbaSJiri Olsa static int test__checkevent_pmu(struct evlist *evlist)
603945aea22SJiri Olsa {
604945aea22SJiri Olsa
605515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
606945aea22SJiri Olsa
6076484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
6081fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
6099854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 10));
6101fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1);
6111fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2);
612204e7c49SRob Herring TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);
613ee4c7588SJiri Olsa /*
61478e1bc25SArnaldo Carvalho de Melo * The period value gets configured within evlist__config,
615ee4c7588SJiri Olsa * while this test executes only parse events method.
616ee4c7588SJiri Olsa */
6171fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
618945aea22SJiri Olsa
6197741e03eSIan Rogers return TEST_OK;
620945aea22SJiri Olsa }
621945aea22SJiri Olsa
622378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
test__checkevent_list(struct evlist * evlist)62363503dbaSJiri Olsa static int test__checkevent_list(struct evlist *evlist)
624945aea22SJiri Olsa {
625515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
626945aea22SJiri Olsa
627aefde50aSIan Rogers TEST_ASSERT_VAL("wrong number of entries", 3 <= evlist->core.nr_entries);
628945aea22SJiri Olsa
629945aea22SJiri Olsa /* r1 */
630aefde50aSIan Rogers TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT != evsel->core.attr.type);
631aefde50aSIan Rogers while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
6329854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
6331fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);
6341fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
635204e7c49SRob Herring TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);
6361fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
6371fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
6381fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
6391fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
640aefde50aSIan Rogers evsel = evsel__next(evsel);
641aefde50aSIan Rogers }
642945aea22SJiri Olsa
64343f322b4SRiku Voipio /* syscalls:sys_enter_openat:k */
6441fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
645945aea22SJiri Olsa TEST_ASSERT_VAL("wrong sample_type",
6461fc632ceSJiri Olsa PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
6471fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
6481fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
6491fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
6501fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
6511fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
652945aea22SJiri Olsa
653945aea22SJiri Olsa /* 1:1:hp */
654e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
6551fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
6569854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
6571fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
6581fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
6591fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
6601fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
661945aea22SJiri Olsa
6627741e03eSIan Rogers return TEST_OK;
663945aea22SJiri Olsa }
664378ef0f5SIan Rogers #endif
665945aea22SJiri Olsa
test__checkevent_pmu_name(struct evlist * evlist)66663503dbaSJiri Olsa static int test__checkevent_pmu_name(struct evlist *evlist)
667945aea22SJiri Olsa {
668515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
669945aea22SJiri Olsa
670945aea22SJiri Olsa /* cpu/config=1,name=krava/u */
6716484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
6721fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
6739854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
6748ab2e96dSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava"));
675945aea22SJiri Olsa
676945aea22SJiri Olsa /* cpu/config=2/u" */
677e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
6786484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
6791fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
6809854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
681945aea22SJiri Olsa TEST_ASSERT_VAL("wrong name",
6828ab2e96dSArnaldo Carvalho de Melo !strcmp(evsel__name(evsel), "cpu/config=2/u"));
683945aea22SJiri Olsa
6847741e03eSIan Rogers return TEST_OK;
685945aea22SJiri Olsa }
686945aea22SJiri Olsa
test__checkevent_pmu_partial_time_callgraph(struct evlist * evlist)68763503dbaSJiri Olsa static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
68871ef150eSKan Liang {
689515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
69071ef150eSKan Liang
69171ef150eSKan Liang /* cpu/config=1,call-graph=fp,time,period=100000/ */
6926484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
6931fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
6949854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
69571ef150eSKan Liang /*
69678e1bc25SArnaldo Carvalho de Melo * The period, time and callgraph value gets configured within evlist__config,
69771ef150eSKan Liang * while this test executes only parse events method.
69871ef150eSKan Liang */
6991fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
70027de9b2bSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
7011fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
70271ef150eSKan Liang
70371ef150eSKan Liang /* cpu/config=2,call-graph=no,time=0,period=2000/ */
704e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
7051fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
7069854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
70771ef150eSKan Liang /*
70878e1bc25SArnaldo Carvalho de Melo * The period, time and callgraph value gets configured within evlist__config,
70971ef150eSKan Liang * while this test executes only parse events method.
71071ef150eSKan Liang */
7111fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
71227de9b2bSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
7131fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
71471ef150eSKan Liang
7157741e03eSIan Rogers return TEST_OK;
71671ef150eSKan Liang }
71771ef150eSKan Liang
test__checkevent_pmu_events(struct evlist * evlist)71863503dbaSJiri Olsa static int test__checkevent_pmu_events(struct evlist *evlist)
719945aea22SJiri Olsa {
720515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
721945aea22SJiri Olsa
7226484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
7235a52817eSIan Rogers TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||
7245a52817eSIan Rogers strcmp(evsel->pmu_name, "cpu"));
725945aea22SJiri Olsa TEST_ASSERT_VAL("wrong exclude_user",
7261fc632ceSJiri Olsa !evsel->core.attr.exclude_user);
727945aea22SJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel",
7281fc632ceSJiri Olsa evsel->core.attr.exclude_kernel);
7291fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
7301fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
7311fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
7320997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
733945aea22SJiri Olsa
7347741e03eSIan Rogers return TEST_OK;
735945aea22SJiri Olsa }
736945aea22SJiri Olsa
737ffe59788SKan Liang
test__checkevent_pmu_events_mix(struct evlist * evlist)73863503dbaSJiri Olsa static int test__checkevent_pmu_events_mix(struct evlist *evlist)
739ffe59788SKan Liang {
74027c9fcfcSIan Rogers struct evsel *evsel = NULL;
741ffe59788SKan Liang
74227c9fcfcSIan Rogers /*
74327c9fcfcSIan Rogers * The wild card event will be opened at least once, but it may be
74427c9fcfcSIan Rogers * opened on each core PMU.
74527c9fcfcSIan Rogers */
74627c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries >= 2);
74727c9fcfcSIan Rogers for (int i = 0; i < evlist->core.nr_entries - 1; i++) {
74827c9fcfcSIan Rogers evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
749ffe59788SKan Liang /* pmu-event:u */
750ffe59788SKan Liang TEST_ASSERT_VAL("wrong exclude_user",
7511fc632ceSJiri Olsa !evsel->core.attr.exclude_user);
752ffe59788SKan Liang TEST_ASSERT_VAL("wrong exclude_kernel",
7531fc632ceSJiri Olsa evsel->core.attr.exclude_kernel);
7541fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
7551fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
7561fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
7570997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
75827c9fcfcSIan Rogers }
759ffe59788SKan Liang /* cpu/pmu-event/u*/
760e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
76127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong type", evsel__find_pmu(evsel)->is_core);
762ffe59788SKan Liang TEST_ASSERT_VAL("wrong exclude_user",
7631fc632ceSJiri Olsa !evsel->core.attr.exclude_user);
764ffe59788SKan Liang TEST_ASSERT_VAL("wrong exclude_kernel",
7651fc632ceSJiri Olsa evsel->core.attr.exclude_kernel);
7661fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
7671fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
7681fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
7690997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned);
770ffe59788SKan Liang
7717741e03eSIan Rogers return TEST_OK;
772ffe59788SKan Liang }
773ffe59788SKan Liang
test__checkterms_simple(struct list_head * terms)774945aea22SJiri Olsa static int test__checkterms_simple(struct list_head *terms)
775945aea22SJiri Olsa {
7766cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term;
777945aea22SJiri Olsa
778945aea22SJiri Olsa /* config=10 */
7796cee6cd3SArnaldo Carvalho de Melo term = list_entry(terms->next, struct parse_events_term, list);
780945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type term",
781945aea22SJiri Olsa term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
782945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type val",
783945aea22SJiri Olsa term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
784945aea22SJiri Olsa TEST_ASSERT_VAL("wrong val", term->val.num == 10);
7854f9d4f8aSJohn Garry TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));
786945aea22SJiri Olsa
787945aea22SJiri Olsa /* config1 */
7886cee6cd3SArnaldo Carvalho de Melo term = list_entry(term->list.next, struct parse_events_term, list);
789945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type term",
790945aea22SJiri Olsa term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
791945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type val",
792945aea22SJiri Olsa term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
793945aea22SJiri Olsa TEST_ASSERT_VAL("wrong val", term->val.num == 1);
7944f9d4f8aSJohn Garry TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1"));
795945aea22SJiri Olsa
796945aea22SJiri Olsa /* config2=3 */
7976cee6cd3SArnaldo Carvalho de Melo term = list_entry(term->list.next, struct parse_events_term, list);
798945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type term",
799945aea22SJiri Olsa term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
800945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type val",
801945aea22SJiri Olsa term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
802945aea22SJiri Olsa TEST_ASSERT_VAL("wrong val", term->val.num == 3);
8034f9d4f8aSJohn Garry TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2"));
804945aea22SJiri Olsa
805204e7c49SRob Herring /* config3=4 */
806204e7c49SRob Herring term = list_entry(term->list.next, struct parse_events_term, list);
807204e7c49SRob Herring TEST_ASSERT_VAL("wrong type term",
808204e7c49SRob Herring term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3);
809204e7c49SRob Herring TEST_ASSERT_VAL("wrong type val",
810204e7c49SRob Herring term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
811204e7c49SRob Herring TEST_ASSERT_VAL("wrong val", term->val.num == 4);
812204e7c49SRob Herring TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config3"));
813204e7c49SRob Herring
814945aea22SJiri Olsa /* umask=1*/
8156cee6cd3SArnaldo Carvalho de Melo term = list_entry(term->list.next, struct parse_events_term, list);
816945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type term",
817945aea22SJiri Olsa term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
818945aea22SJiri Olsa TEST_ASSERT_VAL("wrong type val",
819945aea22SJiri Olsa term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
820945aea22SJiri Olsa TEST_ASSERT_VAL("wrong val", term->val.num == 1);
821945aea22SJiri Olsa TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
822945aea22SJiri Olsa
8234929e95aSJiri Olsa /*
8244929e95aSJiri Olsa * read
8254929e95aSJiri Olsa *
8264929e95aSJiri Olsa * The perf_pmu__test_parse_init injects 'read' term into
8274929e95aSJiri Olsa * perf_pmu_events_list, so 'read' is evaluated as read term
8284929e95aSJiri Olsa * and not as raw event with 'ead' hex value.
8294929e95aSJiri Olsa */
8304929e95aSJiri Olsa term = list_entry(term->list.next, struct parse_events_term, list);
8314929e95aSJiri Olsa TEST_ASSERT_VAL("wrong type term",
83270c90e4aSIan Rogers term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
8334929e95aSJiri Olsa TEST_ASSERT_VAL("wrong type val",
83470c90e4aSIan Rogers term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
83570c90e4aSIan Rogers TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "read"));
83670c90e4aSIan Rogers TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
8374929e95aSJiri Olsa
8384929e95aSJiri Olsa /*
8394929e95aSJiri Olsa * r0xead
8404929e95aSJiri Olsa *
8414929e95aSJiri Olsa * To be still able to pass 'ead' value with 'r' syntax,
8424929e95aSJiri Olsa * we added support to parse 'r0xHEX' event.
8434929e95aSJiri Olsa */
8444929e95aSJiri Olsa term = list_entry(term->list.next, struct parse_events_term, list);
8454929e95aSJiri Olsa TEST_ASSERT_VAL("wrong type term",
84670c90e4aSIan Rogers term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
8474929e95aSJiri Olsa TEST_ASSERT_VAL("wrong type val",
84870c90e4aSIan Rogers term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
84970c90e4aSIan Rogers TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "r0xead"));
85070c90e4aSIan Rogers TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
8517741e03eSIan Rogers return TEST_OK;
852945aea22SJiri Olsa }
853945aea22SJiri Olsa
test__group1(struct evlist * evlist)85463503dbaSJiri Olsa static int test__group1(struct evlist *evlist)
855945aea22SJiri Olsa {
85632dcd021SJiri Olsa struct evsel *evsel, *leader;
857945aea22SJiri Olsa
85827c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
859bcd981dbSJames Clark evlist->core.nr_entries == (num_core_entries() * 2));
86027c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
861bcd981dbSJames Clark evlist__nr_groups(evlist) == num_core_entries());
862945aea22SJiri Olsa
863bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
864945aea22SJiri Olsa /* instructions:k */
86527c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
8661fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
8679854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
8681fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
8691fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
8701fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
8711fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
8721fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
8731fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
874c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
8755643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
8762bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
877a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
878945aea22SJiri Olsa
879945aea22SJiri Olsa /* cycles:upp */
880e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
8811fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
8829854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
8831fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
8841fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
8851fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
886945aea22SJiri Olsa /* use of precise requires exclude_guest */
8871fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
8881fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
8891fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
890fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
8912bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
892a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
89327c9fcfcSIan Rogers }
8947741e03eSIan Rogers return TEST_OK;
895945aea22SJiri Olsa }
896945aea22SJiri Olsa
test__group2(struct evlist * evlist)89763503dbaSJiri Olsa static int test__group2(struct evlist *evlist)
898945aea22SJiri Olsa {
89927c9fcfcSIan Rogers struct evsel *evsel, *leader = NULL;
900945aea22SJiri Olsa
90127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
902bcd981dbSJames Clark evlist->core.nr_entries == (2 * num_core_entries() + 1));
90327c9fcfcSIan Rogers /*
90427c9fcfcSIan Rogers * TODO: Currently the software event won't be grouped with the hardware
90527c9fcfcSIan Rogers * event except for 1 PMU.
90627c9fcfcSIan Rogers */
9079d2dc632SIan Rogers TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
908945aea22SJiri Olsa
90927c9fcfcSIan Rogers evlist__for_each_entry(evlist, evsel) {
91027c9fcfcSIan Rogers if (evsel->core.attr.type == PERF_TYPE_SOFTWARE) {
911945aea22SJiri Olsa /* faults + :ku modifier */
91227c9fcfcSIan Rogers leader = evsel;
91327c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong config",
91427c9fcfcSIan Rogers test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
9151fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
9161fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
9171fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
918943b69acSJin Yao TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
9191fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
9201fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
921c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
9225643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
9232bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
924a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
92527c9fcfcSIan Rogers continue;
92627c9fcfcSIan Rogers }
92727c9fcfcSIan Rogers if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&
92827c9fcfcSIan Rogers test_config(evsel, PERF_COUNT_HW_CACHE_REFERENCES)) {
929945aea22SJiri Olsa /* cache-references + :u modifier */
9301fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
9311fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
9321fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
9331fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
9341fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
9351fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
93627c9fcfcSIan Rogers if (evsel__has_leader(evsel, leader))
9372bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
938a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
93927c9fcfcSIan Rogers continue;
94027c9fcfcSIan Rogers }
941945aea22SJiri Olsa /* cycles:k */
9421fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
9439854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
9441fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
9451fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
9461fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
9471fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
9481fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
9491fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
950c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
951a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
95227c9fcfcSIan Rogers }
9537741e03eSIan Rogers return TEST_OK;
954945aea22SJiri Olsa }
955945aea22SJiri Olsa
956378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
test__group3(struct evlist * evlist __maybe_unused)95763503dbaSJiri Olsa static int test__group3(struct evlist *evlist __maybe_unused)
958945aea22SJiri Olsa {
95927c9fcfcSIan Rogers struct evsel *evsel, *group1_leader = NULL, *group2_leader = NULL;
960945aea22SJiri Olsa
96127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
96227c9fcfcSIan Rogers evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus() + 2));
96327c9fcfcSIan Rogers /*
96427c9fcfcSIan Rogers * Currently the software event won't be grouped with the hardware event
96527c9fcfcSIan Rogers * except for 1 PMU. This means there are always just 2 groups
96627c9fcfcSIan Rogers * regardless of the number of core PMUs.
96727c9fcfcSIan Rogers */
9689d2dc632SIan Rogers TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));
969945aea22SJiri Olsa
97027c9fcfcSIan Rogers evlist__for_each_entry(evlist, evsel) {
97127c9fcfcSIan Rogers if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
97243f322b4SRiku Voipio /* group1 syscalls:sys_enter_openat:H */
97327c9fcfcSIan Rogers group1_leader = evsel;
974945aea22SJiri Olsa TEST_ASSERT_VAL("wrong sample_type",
97527c9fcfcSIan Rogers evsel->core.attr.sample_type == PERF_TP_SAMPLE_TYPE);
9761fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
9771fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
9781fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
9791fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
9801fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
9811fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
9821fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
983c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
98427c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong group name", !strcmp(evsel->group_name, "group1"));
9855643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
9862bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
987a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
98827c9fcfcSIan Rogers continue;
98927c9fcfcSIan Rogers }
99027c9fcfcSIan Rogers if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&
99127c9fcfcSIan Rogers test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)) {
99227c9fcfcSIan Rogers if (evsel->core.attr.exclude_user) {
993945aea22SJiri Olsa /* group1 cycles:kppp */
99427c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_user",
99527c9fcfcSIan Rogers evsel->core.attr.exclude_user);
99627c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel",
99727c9fcfcSIan Rogers !evsel->core.attr.exclude_kernel);
9981fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
999945aea22SJiri Olsa /* use of precise requires exclude_guest */
100027c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude guest",
100127c9fcfcSIan Rogers evsel->core.attr.exclude_guest);
100227c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude host",
100327c9fcfcSIan Rogers !evsel->core.attr.exclude_host);
100427c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong precise_ip",
100527c9fcfcSIan Rogers evsel->core.attr.precise_ip == 3);
100627c9fcfcSIan Rogers if (evsel__has_leader(evsel, group1_leader)) {
1007945aea22SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
100827c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong group_idx",
100927c9fcfcSIan Rogers evsel__group_idx(evsel) == 1);
101027c9fcfcSIan Rogers }
1011a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
101227c9fcfcSIan Rogers } else {
1013945aea22SJiri Olsa /* group2 cycles + G modifier */
101427c9fcfcSIan Rogers group2_leader = evsel;
101527c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_kernel",
101627c9fcfcSIan Rogers !evsel->core.attr.exclude_kernel);
101727c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude_hv",
101827c9fcfcSIan Rogers !evsel->core.attr.exclude_hv);
101927c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude guest",
102027c9fcfcSIan Rogers !evsel->core.attr.exclude_guest);
102127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong exclude host",
102227c9fcfcSIan Rogers evsel->core.attr.exclude_host);
10231fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1024c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
102527c9fcfcSIan Rogers if (evsel->core.nr_members == 2) {
102627c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong group_idx",
102727c9fcfcSIan Rogers evsel__group_idx(evsel) == 0);
102827c9fcfcSIan Rogers }
1029a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
103027c9fcfcSIan Rogers }
103127c9fcfcSIan Rogers continue;
103227c9fcfcSIan Rogers }
103327c9fcfcSIan Rogers if (evsel->core.attr.type == 1) {
1034945aea22SJiri Olsa /* group2 1:3 + G modifier */
10359854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 3));
10361fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
10371fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
10381fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
10391fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
10401fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
10411fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
104227c9fcfcSIan Rogers if (evsel__has_leader(evsel, group2_leader))
10432bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1044a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
104527c9fcfcSIan Rogers continue;
104627c9fcfcSIan Rogers }
1047945aea22SJiri Olsa /* instructions:u */
10481fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
10499854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
10501fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
10511fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
10521fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1053943b69acSJin Yao TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
10541fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
10551fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1056c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1057a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
105827c9fcfcSIan Rogers }
10597741e03eSIan Rogers return TEST_OK;
1060945aea22SJiri Olsa }
1061378ef0f5SIan Rogers #endif
1062945aea22SJiri Olsa
test__group4(struct evlist * evlist __maybe_unused)106363503dbaSJiri Olsa static int test__group4(struct evlist *evlist __maybe_unused)
1064945aea22SJiri Olsa {
106532dcd021SJiri Olsa struct evsel *evsel, *leader;
1066945aea22SJiri Olsa
106727c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1068bcd981dbSJames Clark evlist->core.nr_entries == (num_core_entries() * 2));
106927c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
1070bcd981dbSJames Clark num_core_entries() == evlist__nr_groups(evlist));
1071945aea22SJiri Olsa
1072bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1073945aea22SJiri Olsa /* cycles:u + p */
107427c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
10751fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
10769854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
10771fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
10781fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
10791fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1080945aea22SJiri Olsa /* use of precise requires exclude_guest */
10811fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
10821fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
10831fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);
1084945aea22SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1085c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
10865643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
10872bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1088a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1089945aea22SJiri Olsa
1090945aea22SJiri Olsa /* instructions:kp + p */
1091e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
10921fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
10939854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
10941fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
10951fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
10961fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1097945aea22SJiri Olsa /* use of precise requires exclude_guest */
10981fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
10991fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
11001fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
1101fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
11022bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1103a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
110427c9fcfcSIan Rogers }
11057741e03eSIan Rogers return TEST_OK;
1106945aea22SJiri Olsa }
1107945aea22SJiri Olsa
test__group5(struct evlist * evlist __maybe_unused)110863503dbaSJiri Olsa static int test__group5(struct evlist *evlist __maybe_unused)
1109945aea22SJiri Olsa {
111027c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
1111945aea22SJiri Olsa
111227c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1113bcd981dbSJames Clark evlist->core.nr_entries == (5 * num_core_entries()));
111427c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
1115bcd981dbSJames Clark evlist__nr_groups(evlist) == (2 * num_core_entries()));
1116945aea22SJiri Olsa
1117bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1118945aea22SJiri Olsa /* cycles + G */
111927c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
11201fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
11219854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
11221fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
11231fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
11241fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
11251fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
11261fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
11271fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1128945aea22SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1129c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
11305643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
11312bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1132a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1133945aea22SJiri Olsa
1134945aea22SJiri Olsa /* instructions + G */
1135e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
11361fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
11379854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
11381fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
11391fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
11401fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
11411fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
11421fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
11431fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1144fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
11452bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1146a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
114727c9fcfcSIan Rogers }
1148bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1149945aea22SJiri Olsa /* cycles:G */
1150e470daeaSArnaldo Carvalho de Melo evsel = leader = evsel__next(evsel);
11511fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
11529854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
11531fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
11541fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
11551fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
11561fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
11571fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
11581fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1159945aea22SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1160c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
11615643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
11622bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1163a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1164945aea22SJiri Olsa
1165945aea22SJiri Olsa /* instructions:G */
1166e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
11671fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
11689854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
11691fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
11701fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
11711fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
11721fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
11731fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
11741fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1175fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
11762bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
117727c9fcfcSIan Rogers }
1178bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1179945aea22SJiri Olsa /* cycles */
1180e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
11811fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
11829854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
11831fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
11841fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
11851fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
11861fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
11871fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
11881fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1189c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
119027c9fcfcSIan Rogers }
11917741e03eSIan Rogers return TEST_OK;
1192945aea22SJiri Olsa }
1193945aea22SJiri Olsa
test__group_gh1(struct evlist * evlist)119463503dbaSJiri Olsa static int test__group_gh1(struct evlist *evlist)
11955a30a99fSJiri Olsa {
119627c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
11975a30a99fSJiri Olsa
119827c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1199bcd981dbSJames Clark evlist->core.nr_entries == (2 * num_core_entries()));
120027c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
1201bcd981dbSJames Clark evlist__nr_groups(evlist) == num_core_entries());
12025a30a99fSJiri Olsa
1203bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
12045a30a99fSJiri Olsa /* cycles + :H group modifier */
120527c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
12061fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
12079854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
12081fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
12091fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
12101fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
12111fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
12121fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
12131fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
12145a30a99fSJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1215c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
12165643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
12172bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
12185a30a99fSJiri Olsa
12195a30a99fSJiri Olsa /* cache-misses:G + :H group modifier */
1220e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
12211fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
12229854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
12231fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
12241fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
12251fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
12261fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
12271fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
12281fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1229fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
12302bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
123127c9fcfcSIan Rogers }
12327741e03eSIan Rogers return TEST_OK;
12335a30a99fSJiri Olsa }
12345a30a99fSJiri Olsa
test__group_gh2(struct evlist * evlist)123563503dbaSJiri Olsa static int test__group_gh2(struct evlist *evlist)
12365a30a99fSJiri Olsa {
123727c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
12385a30a99fSJiri Olsa
123927c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1240bcd981dbSJames Clark evlist->core.nr_entries == (2 * num_core_entries()));
124127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
1242bcd981dbSJames Clark evlist__nr_groups(evlist) == num_core_entries());
12435a30a99fSJiri Olsa
1244bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
12455a30a99fSJiri Olsa /* cycles + :G group modifier */
124627c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
12471fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
12489854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
12491fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
12501fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
12511fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
12521fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
12531fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
12541fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
12555a30a99fSJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1256c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
12575643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
12582bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
12595a30a99fSJiri Olsa
12605a30a99fSJiri Olsa /* cache-misses:H + :G group modifier */
1261e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
12621fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
12639854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
12641fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
12651fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
12661fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
12671fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
12681fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
12691fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1270fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
12712bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
127227c9fcfcSIan Rogers }
12737741e03eSIan Rogers return TEST_OK;
12745a30a99fSJiri Olsa }
12755a30a99fSJiri Olsa
test__group_gh3(struct evlist * evlist)127663503dbaSJiri Olsa static int test__group_gh3(struct evlist *evlist)
12775a30a99fSJiri Olsa {
127827c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
12795a30a99fSJiri Olsa
128027c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1281bcd981dbSJames Clark evlist->core.nr_entries == (2 * num_core_entries()));
128227c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
1283bcd981dbSJames Clark evlist__nr_groups(evlist) == num_core_entries());
12845a30a99fSJiri Olsa
1285bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
12865a30a99fSJiri Olsa /* cycles:G + :u group modifier */
128727c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
12881fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
12899854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
12901fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
12911fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
12921fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
12931fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
12941fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
12951fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
12965a30a99fSJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1297c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
12985643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
12992bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
13005a30a99fSJiri Olsa
13015a30a99fSJiri Olsa /* cache-misses:H + :u group modifier */
1302e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
13031fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
13049854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
13051fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
13061fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
13071fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
13081fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
13091fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
13101fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1311fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
13122bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
131327c9fcfcSIan Rogers }
13147741e03eSIan Rogers return TEST_OK;
13155a30a99fSJiri Olsa }
13165a30a99fSJiri Olsa
test__group_gh4(struct evlist * evlist)131763503dbaSJiri Olsa static int test__group_gh4(struct evlist *evlist)
13185a30a99fSJiri Olsa {
131927c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
13205a30a99fSJiri Olsa
132127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1322bcd981dbSJames Clark evlist->core.nr_entries == (2 * num_core_entries()));
132327c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of groups",
1324bcd981dbSJames Clark evlist__nr_groups(evlist) == num_core_entries());
13255a30a99fSJiri Olsa
1326bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
13275a30a99fSJiri Olsa /* cycles:G + :uG group modifier */
132827c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
13291fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
13309854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
13311fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
13321fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
13331fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
13341fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
13351fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
13361fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
13375a30a99fSJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1338c754c382SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
13395643b1a5SJiri Olsa TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
13402bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
13415a30a99fSJiri Olsa
13425a30a99fSJiri Olsa /* cache-misses:H + :uG group modifier */
1343e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
13441fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
13459854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
13461fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
13471fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
13481fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
13491fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
13501fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
13511fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1352fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
13532bb72dbbSArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
135427c9fcfcSIan Rogers }
13557741e03eSIan Rogers return TEST_OK;
13565a30a99fSJiri Olsa }
13575a30a99fSJiri Olsa
test__leader_sample1(struct evlist * evlist)135863503dbaSJiri Olsa static int test__leader_sample1(struct evlist *evlist)
1359a9f93f97SJiri Olsa {
136027c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
1361a9f93f97SJiri Olsa
136227c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1363bcd981dbSJames Clark evlist->core.nr_entries == (3 * num_core_entries()));
1364a9f93f97SJiri Olsa
1365bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1366a9f93f97SJiri Olsa /* cycles - sampling group leader */
136727c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
13681fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
13699854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
13701fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
13711fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
13721fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
13731fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
13741fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
13751fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1376a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1377fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1378a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1379a9f93f97SJiri Olsa
1380a9f93f97SJiri Olsa /* cache-misses - not sampling */
1381e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
13821fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
13839854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
13841fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
13851fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
13861fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
13871fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
13881fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
13891fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1390fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1391a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1392a9f93f97SJiri Olsa
1393a9f93f97SJiri Olsa /* branch-misses - not sampling */
1394e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
13951fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
13969854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
13971fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
13981fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
13991fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
14001fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
14011fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
14021fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1403a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1404fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1405a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
140627c9fcfcSIan Rogers }
14077741e03eSIan Rogers return TEST_OK;
1408a9f93f97SJiri Olsa }
1409a9f93f97SJiri Olsa
test__leader_sample2(struct evlist * evlist __maybe_unused)141063503dbaSJiri Olsa static int test__leader_sample2(struct evlist *evlist __maybe_unused)
1411a9f93f97SJiri Olsa {
141227c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
1413a9f93f97SJiri Olsa
141427c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1415bcd981dbSJames Clark evlist->core.nr_entries == (2 * num_core_entries()));
1416a9f93f97SJiri Olsa
1417bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1418a9f93f97SJiri Olsa /* instructions - sampling group leader */
141927c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
14201fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
14219854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
14221fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14231fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
14241fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
14251fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
14261fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
14271fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1428a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1429fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1430a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1431a9f93f97SJiri Olsa
1432a9f93f97SJiri Olsa /* branch-misses - not sampling */
1433e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
14341fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
14359854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
14361fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14371fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
14381fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
14391fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
14401fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
14411fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1442a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1443fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1444a9f93f97SJiri Olsa TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
144527c9fcfcSIan Rogers }
14467741e03eSIan Rogers return TEST_OK;
1447a9f93f97SJiri Olsa }
1448a9f93f97SJiri Olsa
test__checkevent_pinned_modifier(struct evlist * evlist)144963503dbaSJiri Olsa static int test__checkevent_pinned_modifier(struct evlist *evlist)
1450c9ee780fSMichael Ellerman {
145127c9fcfcSIan Rogers struct evsel *evsel = NULL;
1452c9ee780fSMichael Ellerman
145327c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1454bcd981dbSJames Clark evlist->core.nr_entries == num_core_entries());
145527c9fcfcSIan Rogers
1456bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
145727c9fcfcSIan Rogers evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
14581fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14591fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
14601fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
14611fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
14621fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
146327c9fcfcSIan Rogers }
1464c9ee780fSMichael Ellerman return test__checkevent_symbolic_name(evlist);
1465c9ee780fSMichael Ellerman }
1466c9ee780fSMichael Ellerman
test__pinned_group(struct evlist * evlist)146763503dbaSJiri Olsa static int test__pinned_group(struct evlist *evlist)
1468c9ee780fSMichael Ellerman {
146927c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
1470c9ee780fSMichael Ellerman
147127c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1472bcd981dbSJames Clark evlist->core.nr_entries == (3 * num_core_entries()));
1473c9ee780fSMichael Ellerman
1474bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
1475c9ee780fSMichael Ellerman /* cycles - group leader */
147627c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
14771fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
14789854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1479c9ee780fSMichael Ellerman TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1480fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
148127c9fcfcSIan Rogers /* TODO: The group modifier is not copied to the split group leader. */
148227c9fcfcSIan Rogers if (perf_pmus__num_core_pmus() == 1)
14831fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1484c9ee780fSMichael Ellerman
1485c9ee780fSMichael Ellerman /* cache-misses - can not be pinned, but will go on with the leader */
1486e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
14871fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
14889854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
14891fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1490c9ee780fSMichael Ellerman
1491c9ee780fSMichael Ellerman /* branch-misses - ditto */
1492e470daeaSArnaldo Carvalho de Melo evsel = evsel__next(evsel);
14939854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
14941fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
149527c9fcfcSIan Rogers }
14967741e03eSIan Rogers return TEST_OK;
1497c9ee780fSMichael Ellerman }
1498c9ee780fSMichael Ellerman
test__checkevent_exclusive_modifier(struct evlist * evlist)14990997a266SAndi Kleen static int test__checkevent_exclusive_modifier(struct evlist *evlist)
15000997a266SAndi Kleen {
15010997a266SAndi Kleen struct evsel *evsel = evlist__first(evlist);
15020997a266SAndi Kleen
15030997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
15040997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
15050997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
15060997a266SAndi Kleen TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
15070997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
15080997a266SAndi Kleen
15090997a266SAndi Kleen return test__checkevent_symbolic_name(evlist);
15100997a266SAndi Kleen }
15110997a266SAndi Kleen
test__exclusive_group(struct evlist * evlist)15120997a266SAndi Kleen static int test__exclusive_group(struct evlist *evlist)
15130997a266SAndi Kleen {
151427c9fcfcSIan Rogers struct evsel *evsel = NULL, *leader;
15150997a266SAndi Kleen
151627c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1517bcd981dbSJames Clark evlist->core.nr_entries == 3 * num_core_entries());
15180997a266SAndi Kleen
1519bcd981dbSJames Clark for (int i = 0; i < num_core_entries(); i++) {
15200997a266SAndi Kleen /* cycles - group leader */
152127c9fcfcSIan Rogers evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
15220997a266SAndi Kleen TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
15239854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
15240997a266SAndi Kleen TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1525fba7c866SJiri Olsa TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
152627c9fcfcSIan Rogers /* TODO: The group modifier is not copied to the split group leader. */
152727c9fcfcSIan Rogers if (perf_pmus__num_core_pmus() == 1)
15280997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
15290997a266SAndi Kleen
15300997a266SAndi Kleen /* cache-misses - can not be pinned, but will go on with the leader */
15310997a266SAndi Kleen evsel = evsel__next(evsel);
15320997a266SAndi Kleen TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
15339854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
15340997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
15350997a266SAndi Kleen
15360997a266SAndi Kleen /* branch-misses - ditto */
15370997a266SAndi Kleen evsel = evsel__next(evsel);
15389854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
15390997a266SAndi Kleen TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
154027c9fcfcSIan Rogers }
15417741e03eSIan Rogers return TEST_OK;
15420997a266SAndi Kleen }
test__checkevent_breakpoint_len(struct evlist * evlist)154363503dbaSJiri Olsa static int test__checkevent_breakpoint_len(struct evlist *evlist)
1544ec32398cSJacob Shin {
1545515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1546ec32398cSJacob Shin
15476484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
15481fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
15499854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
1550ec32398cSJacob Shin TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
15511fc632ceSJiri Olsa evsel->core.attr.bp_type);
1552ec32398cSJacob Shin TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
15531fc632ceSJiri Olsa evsel->core.attr.bp_len);
1554ec32398cSJacob Shin
15557741e03eSIan Rogers return TEST_OK;
1556ec32398cSJacob Shin }
1557ec32398cSJacob Shin
test__checkevent_breakpoint_len_w(struct evlist * evlist)155863503dbaSJiri Olsa static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
1559ec32398cSJacob Shin {
1560515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1561ec32398cSJacob Shin
15626484d2f9SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
15631fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
15649854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
1565ec32398cSJacob Shin TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
15661fc632ceSJiri Olsa evsel->core.attr.bp_type);
1567ec32398cSJacob Shin TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
15681fc632ceSJiri Olsa evsel->core.attr.bp_len);
1569ec32398cSJacob Shin
15707741e03eSIan Rogers return TEST_OK;
1571ec32398cSJacob Shin }
1572ec32398cSJacob Shin
1573ec32398cSJacob Shin static int
test__checkevent_breakpoint_len_rw_modifier(struct evlist * evlist)157463503dbaSJiri Olsa test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
1575ec32398cSJacob Shin {
1576515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1577ec32398cSJacob Shin
15781fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
15791fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
15801fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
15811fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1582ec32398cSJacob Shin
1583ec32398cSJacob Shin return test__checkevent_breakpoint_rw(evlist);
1584ec32398cSJacob Shin }
1585ec32398cSJacob Shin
test__checkevent_precise_max_modifier(struct evlist * evlist)158663503dbaSJiri Olsa static int test__checkevent_precise_max_modifier(struct evlist *evlist)
1587ddd83c97SJiri Olsa {
1588515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1589ddd83c97SJiri Olsa
159027c9fcfcSIan Rogers TEST_ASSERT_VAL("wrong number of entries",
1591bcd981dbSJames Clark evlist->core.nr_entries == 1 + num_core_entries());
15921fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
15939854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_TASK_CLOCK));
15947741e03eSIan Rogers return TEST_OK;
1595ddd83c97SJiri Olsa }
1596ddd83c97SJiri Olsa
test__checkevent_config_symbol(struct evlist * evlist)159763503dbaSJiri Olsa static int test__checkevent_config_symbol(struct evlist *evlist)
159810bf358aSWang Nan {
1599515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
160010bf358aSWang Nan
1601ce1d3bc2SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "insn"));
16027741e03eSIan Rogers return TEST_OK;
160310bf358aSWang Nan }
160410bf358aSWang Nan
test__checkevent_config_raw(struct evlist * evlist)160563503dbaSJiri Olsa static int test__checkevent_config_raw(struct evlist *evlist)
160610bf358aSWang Nan {
1607515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
160810bf358aSWang Nan
1609ce1d3bc2SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "rawpmu"));
16107741e03eSIan Rogers return TEST_OK;
161110bf358aSWang Nan }
161210bf358aSWang Nan
test__checkevent_config_num(struct evlist * evlist)161363503dbaSJiri Olsa static int test__checkevent_config_num(struct evlist *evlist)
161410bf358aSWang Nan {
1615515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
161610bf358aSWang Nan
1617ce1d3bc2SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "numpmu"));
16187741e03eSIan Rogers return TEST_OK;
161910bf358aSWang Nan }
162010bf358aSWang Nan
test__checkevent_config_cache(struct evlist * evlist)162163503dbaSJiri Olsa static int test__checkevent_config_cache(struct evlist *evlist)
162243d0b978SWang Nan {
1623515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
162443d0b978SWang Nan
1625ce1d3bc2SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "cachepmu"));
16264a7c4eafSIan Rogers return test__checkevent_genhw(evlist);
162743d0b978SWang Nan }
162810bf358aSWang Nan
test__pmu_cpu_valid(void)16298f8c1068SIan Rogers static bool test__pmu_cpu_valid(void)
16308f8c1068SIan Rogers {
16311eaf496eSIan Rogers return !!perf_pmus__find("cpu");
16328f8c1068SIan Rogers }
16338f8c1068SIan Rogers
test__pmu_cpu_event_valid(void)163407d2b820SIan Rogers static bool test__pmu_cpu_event_valid(void)
163507d2b820SIan Rogers {
163607d2b820SIan Rogers struct perf_pmu *pmu = perf_pmus__find("cpu");
163707d2b820SIan Rogers
163807d2b820SIan Rogers if (!pmu)
163907d2b820SIan Rogers return false;
164007d2b820SIan Rogers
164107d2b820SIan Rogers return perf_pmu__has_format(pmu, "event");
164207d2b820SIan Rogers }
164307d2b820SIan Rogers
test__intel_pt_valid(void)164416ddcfbfSJiri Olsa static bool test__intel_pt_valid(void)
164516ddcfbfSJiri Olsa {
16461eaf496eSIan Rogers return !!perf_pmus__find("intel_pt");
164716ddcfbfSJiri Olsa }
164816ddcfbfSJiri Olsa
test__intel_pt(struct evlist * evlist)164963503dbaSJiri Olsa static int test__intel_pt(struct evlist *evlist)
1650b3f58c8dSArnaldo Carvalho de Melo {
1651515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1652b3f58c8dSArnaldo Carvalho de Melo
1653ce1d3bc2SArnaldo Carvalho de Melo TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "intel_pt//u"));
16547741e03eSIan Rogers return TEST_OK;
1655b3f58c8dSArnaldo Carvalho de Melo }
1656b3f58c8dSArnaldo Carvalho de Melo
test__checkevent_complex_name(struct evlist * evlist)165763503dbaSJiri Olsa static int test__checkevent_complex_name(struct evlist *evlist)
165806dc5bf2SAlexey Budankov {
1659515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
166006dc5bf2SAlexey Budankov
16619854934bSIan Rogers TEST_ASSERT_VAL("wrong complex name parsing",
16629854934bSIan Rogers evsel__name_is(evsel,
16639854934bSIan Rogers "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks"));
16647741e03eSIan Rogers return TEST_OK;
166506dc5bf2SAlexey Budankov }
166606dc5bf2SAlexey Budankov
test__checkevent_raw_pmu(struct evlist * evlist)16673a6c51e4SJiri Olsa static int test__checkevent_raw_pmu(struct evlist *evlist)
16683a6c51e4SJiri Olsa {
16693a6c51e4SJiri Olsa struct evsel *evsel = evlist__first(evlist);
16703a6c51e4SJiri Olsa
16713a6c51e4SJiri Olsa TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
16723a6c51e4SJiri Olsa TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
16739854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a));
16747741e03eSIan Rogers return TEST_OK;
16753a6c51e4SJiri Olsa }
16763a6c51e4SJiri Olsa
test__sym_event_slash(struct evlist * evlist)167763503dbaSJiri Olsa static int test__sym_event_slash(struct evlist *evlist)
1678714a92d8SJiri Olsa {
1679515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1680714a92d8SJiri Olsa
16811fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
16829854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
16831fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
16847741e03eSIan Rogers return TEST_OK;
1685714a92d8SJiri Olsa }
1686714a92d8SJiri Olsa
test__sym_event_dc(struct evlist * evlist)168763503dbaSJiri Olsa static int test__sym_event_dc(struct evlist *evlist)
1688714a92d8SJiri Olsa {
1689515dbe48SJiri Olsa struct evsel *evsel = evlist__first(evlist);
1690714a92d8SJiri Olsa
16911fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
16929854934bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
16931fc632ceSJiri Olsa TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
16947741e03eSIan Rogers return TEST_OK;
1695714a92d8SJiri Olsa }
1696714a92d8SJiri Olsa
test__term_equal_term(struct evlist * evlist)1697e831f3ccSIan Rogers static int test__term_equal_term(struct evlist *evlist)
1698e831f3ccSIan Rogers {
1699e831f3ccSIan Rogers struct evsel *evsel = evlist__first(evlist);
1700e831f3ccSIan Rogers
1701e831f3ccSIan Rogers TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1702e831f3ccSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1703e831f3ccSIan Rogers TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "name") == 0);
1704e831f3ccSIan Rogers return TEST_OK;
1705e831f3ccSIan Rogers }
1706e831f3ccSIan Rogers
test__term_equal_legacy(struct evlist * evlist)17072aadca4bSIan Rogers static int test__term_equal_legacy(struct evlist *evlist)
17082aadca4bSIan Rogers {
17092aadca4bSIan Rogers struct evsel *evsel = evlist__first(evlist);
17102aadca4bSIan Rogers
17112aadca4bSIan Rogers TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
17122aadca4bSIan Rogers TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
17132aadca4bSIan Rogers TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "l1d") == 0);
17142aadca4bSIan Rogers return TEST_OK;
17152aadca4bSIan Rogers }
17162aadca4bSIan Rogers
1717378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
count_tracepoints(void)171882ce75d9SJiri Olsa static int count_tracepoints(void)
171982ce75d9SJiri Olsa {
172082ce75d9SJiri Olsa struct dirent *events_ent;
172182ce75d9SJiri Olsa DIR *events_dir;
172282ce75d9SJiri Olsa int cnt = 0;
172382ce75d9SJiri Olsa
17247014e0e3SArnaldo Carvalho de Melo events_dir = tracing_events__opendir();
172582ce75d9SJiri Olsa
172682ce75d9SJiri Olsa TEST_ASSERT_VAL("Can't open events dir", events_dir);
172782ce75d9SJiri Olsa
172882ce75d9SJiri Olsa while ((events_ent = readdir(events_dir))) {
172925a7d914SArnaldo Carvalho de Melo char *sys_path;
173082ce75d9SJiri Olsa struct dirent *sys_ent;
173182ce75d9SJiri Olsa DIR *sys_dir;
173282ce75d9SJiri Olsa
173382ce75d9SJiri Olsa if (!strcmp(events_ent->d_name, ".")
173482ce75d9SJiri Olsa || !strcmp(events_ent->d_name, "..")
173582ce75d9SJiri Olsa || !strcmp(events_ent->d_name, "enable")
173682ce75d9SJiri Olsa || !strcmp(events_ent->d_name, "header_event")
173782ce75d9SJiri Olsa || !strcmp(events_ent->d_name, "header_page"))
173882ce75d9SJiri Olsa continue;
173982ce75d9SJiri Olsa
174025a7d914SArnaldo Carvalho de Melo sys_path = get_events_file(events_ent->d_name);
174125a7d914SArnaldo Carvalho de Melo TEST_ASSERT_VAL("Can't get sys path", sys_path);
174282ce75d9SJiri Olsa
174382ce75d9SJiri Olsa sys_dir = opendir(sys_path);
174482ce75d9SJiri Olsa TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
174582ce75d9SJiri Olsa
174682ce75d9SJiri Olsa while ((sys_ent = readdir(sys_dir))) {
174782ce75d9SJiri Olsa if (!strcmp(sys_ent->d_name, ".")
174882ce75d9SJiri Olsa || !strcmp(sys_ent->d_name, "..")
174982ce75d9SJiri Olsa || !strcmp(sys_ent->d_name, "enable")
175082ce75d9SJiri Olsa || !strcmp(sys_ent->d_name, "filter"))
175182ce75d9SJiri Olsa continue;
175282ce75d9SJiri Olsa
175382ce75d9SJiri Olsa cnt++;
175482ce75d9SJiri Olsa }
175582ce75d9SJiri Olsa
175682ce75d9SJiri Olsa closedir(sys_dir);
175725a7d914SArnaldo Carvalho de Melo put_events_file(sys_path);
175882ce75d9SJiri Olsa }
175982ce75d9SJiri Olsa
176082ce75d9SJiri Olsa closedir(events_dir);
176182ce75d9SJiri Olsa return cnt;
176282ce75d9SJiri Olsa }
176382ce75d9SJiri Olsa
test__all_tracepoints(struct evlist * evlist)176463503dbaSJiri Olsa static int test__all_tracepoints(struct evlist *evlist)
176582ce75d9SJiri Olsa {
176682ce75d9SJiri Olsa TEST_ASSERT_VAL("wrong events count",
17676484d2f9SJiri Olsa count_tracepoints() == evlist->core.nr_entries);
176882ce75d9SJiri Olsa
176982ce75d9SJiri Olsa return test__checkevent_tracepoint_multi(evlist);
177082ce75d9SJiri Olsa }
1771378ef0f5SIan Rogers #endif /* HAVE_LIBTRACEVENT */
177282ce75d9SJiri Olsa
177323b6339bSArnaldo Carvalho de Melo struct evlist_test {
1774945aea22SJiri Olsa const char *name;
177516ddcfbfSJiri Olsa bool (*valid)(void);
177663503dbaSJiri Olsa int (*check)(struct evlist *evlist);
1777945aea22SJiri Olsa };
1778945aea22SJiri Olsa
17798252e791SIan Rogers static const struct evlist_test test__events[] = {
1780378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1781615b8f99SAlexander Yarygin {
178243f322b4SRiku Voipio .name = "syscalls:sys_enter_openat",
1783945aea22SJiri Olsa .check = test__checkevent_tracepoint,
17848252e791SIan Rogers /* 0 */
1785945aea22SJiri Olsa },
1786615b8f99SAlexander Yarygin {
1787945aea22SJiri Olsa .name = "syscalls:*",
1788945aea22SJiri Olsa .check = test__checkevent_tracepoint_multi,
17898252e791SIan Rogers /* 1 */
1790945aea22SJiri Olsa },
1791378ef0f5SIan Rogers #endif
1792615b8f99SAlexander Yarygin {
1793945aea22SJiri Olsa .name = "r1a",
1794945aea22SJiri Olsa .check = test__checkevent_raw,
17958252e791SIan Rogers /* 2 */
1796945aea22SJiri Olsa },
1797615b8f99SAlexander Yarygin {
1798945aea22SJiri Olsa .name = "1:1",
1799945aea22SJiri Olsa .check = test__checkevent_numeric,
18008252e791SIan Rogers /* 3 */
1801945aea22SJiri Olsa },
1802615b8f99SAlexander Yarygin {
1803945aea22SJiri Olsa .name = "instructions",
1804945aea22SJiri Olsa .check = test__checkevent_symbolic_name,
18058252e791SIan Rogers /* 4 */
1806945aea22SJiri Olsa },
1807615b8f99SAlexander Yarygin {
1808945aea22SJiri Olsa .name = "cycles/period=100000,config2/",
1809945aea22SJiri Olsa .check = test__checkevent_symbolic_name_config,
18108252e791SIan Rogers /* 5 */
1811945aea22SJiri Olsa },
1812615b8f99SAlexander Yarygin {
1813945aea22SJiri Olsa .name = "faults",
1814945aea22SJiri Olsa .check = test__checkevent_symbolic_alias,
18158252e791SIan Rogers /* 6 */
1816945aea22SJiri Olsa },
1817615b8f99SAlexander Yarygin {
1818945aea22SJiri Olsa .name = "L1-dcache-load-miss",
1819945aea22SJiri Olsa .check = test__checkevent_genhw,
18208252e791SIan Rogers /* 7 */
1821945aea22SJiri Olsa },
1822615b8f99SAlexander Yarygin {
1823945aea22SJiri Olsa .name = "mem:0",
1824945aea22SJiri Olsa .check = test__checkevent_breakpoint,
18258252e791SIan Rogers /* 8 */
1826945aea22SJiri Olsa },
1827615b8f99SAlexander Yarygin {
1828945aea22SJiri Olsa .name = "mem:0:x",
1829945aea22SJiri Olsa .check = test__checkevent_breakpoint_x,
18308252e791SIan Rogers /* 9 */
1831945aea22SJiri Olsa },
1832615b8f99SAlexander Yarygin {
1833945aea22SJiri Olsa .name = "mem:0:r",
1834945aea22SJiri Olsa .check = test__checkevent_breakpoint_r,
18358252e791SIan Rogers /* 0 */
1836945aea22SJiri Olsa },
1837615b8f99SAlexander Yarygin {
1838945aea22SJiri Olsa .name = "mem:0:w",
1839945aea22SJiri Olsa .check = test__checkevent_breakpoint_w,
18408252e791SIan Rogers /* 1 */
1841945aea22SJiri Olsa },
1842378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1843615b8f99SAlexander Yarygin {
184443f322b4SRiku Voipio .name = "syscalls:sys_enter_openat:k",
1845945aea22SJiri Olsa .check = test__checkevent_tracepoint_modifier,
18468252e791SIan Rogers /* 2 */
1847945aea22SJiri Olsa },
1848615b8f99SAlexander Yarygin {
1849945aea22SJiri Olsa .name = "syscalls:*:u",
1850945aea22SJiri Olsa .check = test__checkevent_tracepoint_multi_modifier,
18518252e791SIan Rogers /* 3 */
1852945aea22SJiri Olsa },
1853378ef0f5SIan Rogers #endif
1854615b8f99SAlexander Yarygin {
1855945aea22SJiri Olsa .name = "r1a:kp",
1856945aea22SJiri Olsa .check = test__checkevent_raw_modifier,
18578252e791SIan Rogers /* 4 */
1858945aea22SJiri Olsa },
1859615b8f99SAlexander Yarygin {
1860945aea22SJiri Olsa .name = "1:1:hp",
1861945aea22SJiri Olsa .check = test__checkevent_numeric_modifier,
18628252e791SIan Rogers /* 5 */
1863945aea22SJiri Olsa },
1864615b8f99SAlexander Yarygin {
1865945aea22SJiri Olsa .name = "instructions:h",
1866945aea22SJiri Olsa .check = test__checkevent_symbolic_name_modifier,
18678252e791SIan Rogers /* 6 */
1868945aea22SJiri Olsa },
1869615b8f99SAlexander Yarygin {
1870945aea22SJiri Olsa .name = "faults:u",
1871945aea22SJiri Olsa .check = test__checkevent_symbolic_alias_modifier,
18728252e791SIan Rogers /* 7 */
1873945aea22SJiri Olsa },
1874615b8f99SAlexander Yarygin {
1875945aea22SJiri Olsa .name = "L1-dcache-load-miss:kp",
1876945aea22SJiri Olsa .check = test__checkevent_genhw_modifier,
18778252e791SIan Rogers /* 8 */
1878945aea22SJiri Olsa },
1879615b8f99SAlexander Yarygin {
1880945aea22SJiri Olsa .name = "mem:0:u",
1881945aea22SJiri Olsa .check = test__checkevent_breakpoint_modifier,
18828252e791SIan Rogers /* 9 */
1883945aea22SJiri Olsa },
1884615b8f99SAlexander Yarygin {
1885945aea22SJiri Olsa .name = "mem:0:x:k",
1886945aea22SJiri Olsa .check = test__checkevent_breakpoint_x_modifier,
18878252e791SIan Rogers /* 0 */
1888945aea22SJiri Olsa },
1889615b8f99SAlexander Yarygin {
1890945aea22SJiri Olsa .name = "mem:0:r:hp",
1891945aea22SJiri Olsa .check = test__checkevent_breakpoint_r_modifier,
18928252e791SIan Rogers /* 1 */
1893945aea22SJiri Olsa },
1894615b8f99SAlexander Yarygin {
1895945aea22SJiri Olsa .name = "mem:0:w:up",
1896945aea22SJiri Olsa .check = test__checkevent_breakpoint_w_modifier,
18978252e791SIan Rogers /* 2 */
1898945aea22SJiri Olsa },
1899378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1900615b8f99SAlexander Yarygin {
190143f322b4SRiku Voipio .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1902945aea22SJiri Olsa .check = test__checkevent_list,
19038252e791SIan Rogers /* 3 */
1904945aea22SJiri Olsa },
1905378ef0f5SIan Rogers #endif
1906615b8f99SAlexander Yarygin {
1907945aea22SJiri Olsa .name = "instructions:G",
1908945aea22SJiri Olsa .check = test__checkevent_exclude_host_modifier,
19098252e791SIan Rogers /* 4 */
1910945aea22SJiri Olsa },
1911615b8f99SAlexander Yarygin {
1912945aea22SJiri Olsa .name = "instructions:H",
1913945aea22SJiri Olsa .check = test__checkevent_exclude_guest_modifier,
19148252e791SIan Rogers /* 5 */
1915945aea22SJiri Olsa },
1916615b8f99SAlexander Yarygin {
1917945aea22SJiri Olsa .name = "mem:0:rw",
1918945aea22SJiri Olsa .check = test__checkevent_breakpoint_rw,
19198252e791SIan Rogers /* 6 */
1920945aea22SJiri Olsa },
1921615b8f99SAlexander Yarygin {
1922945aea22SJiri Olsa .name = "mem:0:rw:kp",
1923945aea22SJiri Olsa .check = test__checkevent_breakpoint_rw_modifier,
19248252e791SIan Rogers /* 7 */
1925945aea22SJiri Olsa },
1926615b8f99SAlexander Yarygin {
1927945aea22SJiri Olsa .name = "{instructions:k,cycles:upp}",
1928945aea22SJiri Olsa .check = test__group1,
19298252e791SIan Rogers /* 8 */
1930945aea22SJiri Olsa },
1931615b8f99SAlexander Yarygin {
1932945aea22SJiri Olsa .name = "{faults:k,cache-references}:u,cycles:k",
1933945aea22SJiri Olsa .check = test__group2,
19348252e791SIan Rogers /* 9 */
1935945aea22SJiri Olsa },
1936378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1937615b8f99SAlexander Yarygin {
193843f322b4SRiku Voipio .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1939945aea22SJiri Olsa .check = test__group3,
19408252e791SIan Rogers /* 0 */
1941945aea22SJiri Olsa },
1942378ef0f5SIan Rogers #endif
1943615b8f99SAlexander Yarygin {
1944945aea22SJiri Olsa .name = "{cycles:u,instructions:kp}:p",
1945945aea22SJiri Olsa .check = test__group4,
19468252e791SIan Rogers /* 1 */
1947945aea22SJiri Olsa },
1948615b8f99SAlexander Yarygin {
1949945aea22SJiri Olsa .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1950945aea22SJiri Olsa .check = test__group5,
19518252e791SIan Rogers /* 2 */
1952945aea22SJiri Olsa },
1953378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1954615b8f99SAlexander Yarygin {
195582ce75d9SJiri Olsa .name = "*:*",
195682ce75d9SJiri Olsa .check = test__all_tracepoints,
19578252e791SIan Rogers /* 3 */
195882ce75d9SJiri Olsa },
1959378ef0f5SIan Rogers #endif
1960615b8f99SAlexander Yarygin {
19615a30a99fSJiri Olsa .name = "{cycles,cache-misses:G}:H",
19625a30a99fSJiri Olsa .check = test__group_gh1,
19638252e791SIan Rogers /* 4 */
19645a30a99fSJiri Olsa },
1965615b8f99SAlexander Yarygin {
19665a30a99fSJiri Olsa .name = "{cycles,cache-misses:H}:G",
19675a30a99fSJiri Olsa .check = test__group_gh2,
19688252e791SIan Rogers /* 5 */
19695a30a99fSJiri Olsa },
1970615b8f99SAlexander Yarygin {
19715a30a99fSJiri Olsa .name = "{cycles:G,cache-misses:H}:u",
19725a30a99fSJiri Olsa .check = test__group_gh3,
19738252e791SIan Rogers /* 6 */
19745a30a99fSJiri Olsa },
1975615b8f99SAlexander Yarygin {
19765a30a99fSJiri Olsa .name = "{cycles:G,cache-misses:H}:uG",
19775a30a99fSJiri Olsa .check = test__group_gh4,
19788252e791SIan Rogers /* 7 */
19795a30a99fSJiri Olsa },
1980615b8f99SAlexander Yarygin {
1981a9f93f97SJiri Olsa .name = "{cycles,cache-misses,branch-misses}:S",
1982a9f93f97SJiri Olsa .check = test__leader_sample1,
19838252e791SIan Rogers /* 8 */
1984a9f93f97SJiri Olsa },
1985615b8f99SAlexander Yarygin {
1986a9f93f97SJiri Olsa .name = "{instructions,branch-misses}:Su",
1987a9f93f97SJiri Olsa .check = test__leader_sample2,
19888252e791SIan Rogers /* 9 */
1989a9f93f97SJiri Olsa },
1990615b8f99SAlexander Yarygin {
1991c9ee780fSMichael Ellerman .name = "instructions:uDp",
1992c9ee780fSMichael Ellerman .check = test__checkevent_pinned_modifier,
19938252e791SIan Rogers /* 0 */
1994c9ee780fSMichael Ellerman },
1995615b8f99SAlexander Yarygin {
1996c9ee780fSMichael Ellerman .name = "{cycles,cache-misses,branch-misses}:D",
1997c9ee780fSMichael Ellerman .check = test__pinned_group,
19988252e791SIan Rogers /* 1 */
1999c9ee780fSMichael Ellerman },
2000ec32398cSJacob Shin {
2001ec32398cSJacob Shin .name = "mem:0/1",
2002ec32398cSJacob Shin .check = test__checkevent_breakpoint_len,
20038252e791SIan Rogers /* 2 */
2004ec32398cSJacob Shin },
2005ec32398cSJacob Shin {
2006ec32398cSJacob Shin .name = "mem:0/2:w",
2007ec32398cSJacob Shin .check = test__checkevent_breakpoint_len_w,
20088252e791SIan Rogers /* 3 */
2009ec32398cSJacob Shin },
2010ec32398cSJacob Shin {
2011ec32398cSJacob Shin .name = "mem:0/4:rw:u",
2012ec32398cSJacob Shin .check = test__checkevent_breakpoint_len_rw_modifier,
20138252e791SIan Rogers /* 4 */
2014ec32398cSJacob Shin },
2015378ef0f5SIan Rogers #if defined(__s390x__) && defined(HAVE_LIBTRACEEVENT)
2016c0bc8c6dSAlexander Yarygin {
2017c0bc8c6dSAlexander Yarygin .name = "kvm-s390:kvm_s390_create_vm",
2018c0bc8c6dSAlexander Yarygin .check = test__checkevent_tracepoint,
201953fe307dSThomas Richter .valid = kvm_s390_create_vm_valid,
20208252e791SIan Rogers /* 0 */
2021c0bc8c6dSAlexander Yarygin },
2022c0bc8c6dSAlexander Yarygin #endif
2023a1e12da4SJiri Olsa {
2024a1e12da4SJiri Olsa .name = "instructions:I",
2025a1e12da4SJiri Olsa .check = test__checkevent_exclude_idle_modifier,
20268252e791SIan Rogers /* 5 */
2027a1e12da4SJiri Olsa },
2028a1e12da4SJiri Olsa {
2029a1e12da4SJiri Olsa .name = "instructions:kIG",
2030a1e12da4SJiri Olsa .check = test__checkevent_exclude_idle_modifier_1,
20318252e791SIan Rogers /* 6 */
2032a1e12da4SJiri Olsa },
2033ddd83c97SJiri Olsa {
2034ddd83c97SJiri Olsa .name = "task-clock:P,cycles",
2035ddd83c97SJiri Olsa .check = test__checkevent_precise_max_modifier,
20368252e791SIan Rogers /* 7 */
2037ddd83c97SJiri Olsa },
203810bf358aSWang Nan {
203910bf358aSWang Nan .name = "instructions/name=insn/",
204010bf358aSWang Nan .check = test__checkevent_config_symbol,
20418252e791SIan Rogers /* 8 */
204210bf358aSWang Nan },
204310bf358aSWang Nan {
204410bf358aSWang Nan .name = "r1234/name=rawpmu/",
204510bf358aSWang Nan .check = test__checkevent_config_raw,
20468252e791SIan Rogers /* 9 */
204710bf358aSWang Nan },
204810bf358aSWang Nan {
204910bf358aSWang Nan .name = "4:0x6530160/name=numpmu/",
205010bf358aSWang Nan .check = test__checkevent_config_num,
20518252e791SIan Rogers /* 0 */
205210bf358aSWang Nan },
205343d0b978SWang Nan {
205443d0b978SWang Nan .name = "L1-dcache-misses/name=cachepmu/",
205543d0b978SWang Nan .check = test__checkevent_config_cache,
20568252e791SIan Rogers /* 1 */
205743d0b978SWang Nan },
2058b3f58c8dSArnaldo Carvalho de Melo {
2059b3f58c8dSArnaldo Carvalho de Melo .name = "intel_pt//u",
206016ddcfbfSJiri Olsa .valid = test__intel_pt_valid,
2061b3f58c8dSArnaldo Carvalho de Melo .check = test__intel_pt,
20628252e791SIan Rogers /* 2 */
2063b3f58c8dSArnaldo Carvalho de Melo },
206406dc5bf2SAlexey Budankov {
206506dc5bf2SAlexey Budankov .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",
206606dc5bf2SAlexey Budankov .check = test__checkevent_complex_name,
20678252e791SIan Rogers /* 3 */
2068714a92d8SJiri Olsa },
2069714a92d8SJiri Olsa {
2070714a92d8SJiri Olsa .name = "cycles//u",
2071714a92d8SJiri Olsa .check = test__sym_event_slash,
20728252e791SIan Rogers /* 4 */
2073714a92d8SJiri Olsa },
2074714a92d8SJiri Olsa {
2075714a92d8SJiri Olsa .name = "cycles:k",
2076714a92d8SJiri Olsa .check = test__sym_event_dc,
20778252e791SIan Rogers /* 5 */
20780997a266SAndi Kleen },
20790997a266SAndi Kleen {
20800997a266SAndi Kleen .name = "instructions:uep",
20810997a266SAndi Kleen .check = test__checkevent_exclusive_modifier,
20828252e791SIan Rogers /* 6 */
20830997a266SAndi Kleen },
20840997a266SAndi Kleen {
20850997a266SAndi Kleen .name = "{cycles,cache-misses,branch-misses}:e",
20860997a266SAndi Kleen .check = test__exclusive_group,
20878252e791SIan Rogers /* 7 */
20880997a266SAndi Kleen },
2089e831f3ccSIan Rogers {
2090e831f3ccSIan Rogers .name = "cycles/name=name/",
2091e831f3ccSIan Rogers .check = test__term_equal_term,
2092e831f3ccSIan Rogers /* 8 */
2093e831f3ccSIan Rogers },
20942aadca4bSIan Rogers {
20952aadca4bSIan Rogers .name = "cycles/name=l1d/",
20962aadca4bSIan Rogers .check = test__term_equal_legacy,
20972aadca4bSIan Rogers /* 9 */
20982aadca4bSIan Rogers },
2099f0617f52SAdrian Hunter {
2100f0617f52SAdrian Hunter .name = "mem:0/name=breakpoint/",
2101f0617f52SAdrian Hunter .check = test__checkevent_breakpoint,
2102f0617f52SAdrian Hunter /* 0 */
2103f0617f52SAdrian Hunter },
2104f0617f52SAdrian Hunter {
2105f0617f52SAdrian Hunter .name = "mem:0:x/name=breakpoint/",
2106f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_x,
2107f0617f52SAdrian Hunter /* 1 */
2108f0617f52SAdrian Hunter },
2109f0617f52SAdrian Hunter {
2110f0617f52SAdrian Hunter .name = "mem:0:r/name=breakpoint/",
2111f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_r,
2112f0617f52SAdrian Hunter /* 2 */
2113f0617f52SAdrian Hunter },
2114f0617f52SAdrian Hunter {
2115f0617f52SAdrian Hunter .name = "mem:0:w/name=breakpoint/",
2116f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_w,
2117f0617f52SAdrian Hunter /* 3 */
2118f0617f52SAdrian Hunter },
2119f0617f52SAdrian Hunter {
2120f0617f52SAdrian Hunter .name = "mem:0/name=breakpoint/u",
2121f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_modifier_name,
2122f0617f52SAdrian Hunter /* 4 */
2123f0617f52SAdrian Hunter },
2124f0617f52SAdrian Hunter {
2125f0617f52SAdrian Hunter .name = "mem:0:x/name=breakpoint/k",
2126f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_x_modifier_name,
2127f0617f52SAdrian Hunter /* 5 */
2128f0617f52SAdrian Hunter },
2129f0617f52SAdrian Hunter {
2130f0617f52SAdrian Hunter .name = "mem:0:r/name=breakpoint/hp",
2131f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_r_modifier_name,
2132f0617f52SAdrian Hunter /* 6 */
2133f0617f52SAdrian Hunter },
2134f0617f52SAdrian Hunter {
2135f0617f52SAdrian Hunter .name = "mem:0:w/name=breakpoint/up",
2136f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_w_modifier_name,
2137f0617f52SAdrian Hunter /* 7 */
2138f0617f52SAdrian Hunter },
2139f0617f52SAdrian Hunter {
2140f0617f52SAdrian Hunter .name = "mem:0:rw/name=breakpoint/",
2141f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_rw,
2142f0617f52SAdrian Hunter /* 8 */
2143f0617f52SAdrian Hunter },
2144f0617f52SAdrian Hunter {
2145f0617f52SAdrian Hunter .name = "mem:0:rw/name=breakpoint/kp",
2146f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_rw_modifier_name,
2147f0617f52SAdrian Hunter /* 9 */
2148f0617f52SAdrian Hunter },
2149f0617f52SAdrian Hunter {
2150f0617f52SAdrian Hunter .name = "mem:0/1/name=breakpoint/",
2151f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_len,
2152f0617f52SAdrian Hunter /* 0 */
2153f0617f52SAdrian Hunter },
2154f0617f52SAdrian Hunter {
2155f0617f52SAdrian Hunter .name = "mem:0/2:w/name=breakpoint/",
2156f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_len_w,
2157f0617f52SAdrian Hunter /* 1 */
2158f0617f52SAdrian Hunter },
2159f0617f52SAdrian Hunter {
2160f0617f52SAdrian Hunter .name = "mem:0/4:rw/name=breakpoint/u",
2161f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_len_rw_modifier,
2162f0617f52SAdrian Hunter /* 2 */
2163f0617f52SAdrian Hunter },
2164f0617f52SAdrian Hunter {
2165f0617f52SAdrian Hunter .name = "mem:0/1/name=breakpoint1/,mem:0/4:rw/name=breakpoint2/",
2166f0617f52SAdrian Hunter .check = test__checkevent_breakpoint_2_events,
2167f0617f52SAdrian Hunter /* 3 */
2168f0617f52SAdrian Hunter },
2169945aea22SJiri Olsa };
2170945aea22SJiri Olsa
21718252e791SIan Rogers static const struct evlist_test test__events_pmu[] = {
2172615b8f99SAlexander Yarygin {
2173*9ea150a8SIan Rogers .name = "cpu/config=10,config1=1,config2=3,period=1000/u",
21748f8c1068SIan Rogers .valid = test__pmu_cpu_valid,
2175945aea22SJiri Olsa .check = test__checkevent_pmu,
21768252e791SIan Rogers /* 0 */
2177945aea22SJiri Olsa },
2178615b8f99SAlexander Yarygin {
2179945aea22SJiri Olsa .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
21808f8c1068SIan Rogers .valid = test__pmu_cpu_valid,
2181945aea22SJiri Olsa .check = test__checkevent_pmu_name,
21828252e791SIan Rogers /* 1 */
2183945aea22SJiri Olsa },
218471ef150eSKan Liang {
218571ef150eSKan Liang .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
21868f8c1068SIan Rogers .valid = test__pmu_cpu_valid,
218771ef150eSKan Liang .check = test__checkevent_pmu_partial_time_callgraph,
21888252e791SIan Rogers /* 2 */
218971ef150eSKan Liang },
219006dc5bf2SAlexey Budankov {
2191a6f39cecSSandipan Das .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
219207d2b820SIan Rogers .valid = test__pmu_cpu_event_valid,
219306dc5bf2SAlexey Budankov .check = test__checkevent_complex_name,
21948252e791SIan Rogers /* 3 */
21953a6c51e4SJiri Olsa },
21963a6c51e4SJiri Olsa {
21973a6c51e4SJiri Olsa .name = "software/r1a/",
21983a6c51e4SJiri Olsa .check = test__checkevent_raw_pmu,
21998252e791SIan Rogers /* 4 */
22003a6c51e4SJiri Olsa },
2201c33cdf54SJiri Olsa {
2202c33cdf54SJiri Olsa .name = "software/r0x1a/",
2203c33cdf54SJiri Olsa .check = test__checkevent_raw_pmu,
22048252e791SIan Rogers /* 5 */
2205c33cdf54SJiri Olsa },
22066fd1e519SIan Rogers {
22076fd1e519SIan Rogers .name = "cpu/L1-dcache-load-miss/",
22086fd1e519SIan Rogers .valid = test__pmu_cpu_valid,
22096fd1e519SIan Rogers .check = test__checkevent_genhw,
22106fd1e519SIan Rogers /* 6 */
22116fd1e519SIan Rogers },
22126fd1e519SIan Rogers {
22136fd1e519SIan Rogers .name = "cpu/L1-dcache-load-miss/kp",
22146fd1e519SIan Rogers .valid = test__pmu_cpu_valid,
22156fd1e519SIan Rogers .check = test__checkevent_genhw_modifier,
22166fd1e519SIan Rogers /* 7 */
22176fd1e519SIan Rogers },
22186fd1e519SIan Rogers {
22196fd1e519SIan Rogers .name = "cpu/L1-dcache-misses,name=cachepmu/",
22206fd1e519SIan Rogers .valid = test__pmu_cpu_valid,
22216fd1e519SIan Rogers .check = test__checkevent_config_cache,
22226fd1e519SIan Rogers /* 8 */
22236fd1e519SIan Rogers },
22245ea8f2ccSIan Rogers {
22255ea8f2ccSIan Rogers .name = "cpu/instructions/",
22265ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22275ea8f2ccSIan Rogers .check = test__checkevent_symbolic_name,
22285ea8f2ccSIan Rogers /* 9 */
22295ea8f2ccSIan Rogers },
22305ea8f2ccSIan Rogers {
22315ea8f2ccSIan Rogers .name = "cpu/cycles,period=100000,config2/",
22325ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22335ea8f2ccSIan Rogers .check = test__checkevent_symbolic_name_config,
22345ea8f2ccSIan Rogers /* 0 */
22355ea8f2ccSIan Rogers },
22365ea8f2ccSIan Rogers {
22375ea8f2ccSIan Rogers .name = "cpu/instructions/h",
22385ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22395ea8f2ccSIan Rogers .check = test__checkevent_symbolic_name_modifier,
22405ea8f2ccSIan Rogers /* 1 */
22415ea8f2ccSIan Rogers },
22425ea8f2ccSIan Rogers {
22435ea8f2ccSIan Rogers .name = "cpu/instructions/G",
22445ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22455ea8f2ccSIan Rogers .check = test__checkevent_exclude_host_modifier,
22465ea8f2ccSIan Rogers /* 2 */
22475ea8f2ccSIan Rogers },
22485ea8f2ccSIan Rogers {
22495ea8f2ccSIan Rogers .name = "cpu/instructions/H",
22505ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22515ea8f2ccSIan Rogers .check = test__checkevent_exclude_guest_modifier,
22525ea8f2ccSIan Rogers /* 3 */
22535ea8f2ccSIan Rogers },
22545ea8f2ccSIan Rogers {
22555ea8f2ccSIan Rogers .name = "{cpu/instructions/k,cpu/cycles/upp}",
22565ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22575ea8f2ccSIan Rogers .check = test__group1,
22585ea8f2ccSIan Rogers /* 4 */
22595ea8f2ccSIan Rogers },
22605ea8f2ccSIan Rogers {
22615ea8f2ccSIan Rogers .name = "{cpu/cycles/u,cpu/instructions/kp}:p",
22625ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22635ea8f2ccSIan Rogers .check = test__group4,
22645ea8f2ccSIan Rogers /* 5 */
22655ea8f2ccSIan Rogers },
22665ea8f2ccSIan Rogers {
22675ea8f2ccSIan Rogers .name = "{cpu/cycles/,cpu/cache-misses/G}:H",
22685ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22695ea8f2ccSIan Rogers .check = test__group_gh1,
22705ea8f2ccSIan Rogers /* 6 */
22715ea8f2ccSIan Rogers },
22725ea8f2ccSIan Rogers {
22735ea8f2ccSIan Rogers .name = "{cpu/cycles/,cpu/cache-misses/H}:G",
22745ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22755ea8f2ccSIan Rogers .check = test__group_gh2,
22765ea8f2ccSIan Rogers /* 7 */
22775ea8f2ccSIan Rogers },
22785ea8f2ccSIan Rogers {
22795ea8f2ccSIan Rogers .name = "{cpu/cycles/G,cpu/cache-misses/H}:u",
22805ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22815ea8f2ccSIan Rogers .check = test__group_gh3,
22825ea8f2ccSIan Rogers /* 8 */
22835ea8f2ccSIan Rogers },
22845ea8f2ccSIan Rogers {
22855ea8f2ccSIan Rogers .name = "{cpu/cycles/G,cpu/cache-misses/H}:uG",
22865ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22875ea8f2ccSIan Rogers .check = test__group_gh4,
22885ea8f2ccSIan Rogers /* 9 */
22895ea8f2ccSIan Rogers },
22905ea8f2ccSIan Rogers {
22915ea8f2ccSIan Rogers .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:S",
22925ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22935ea8f2ccSIan Rogers .check = test__leader_sample1,
22945ea8f2ccSIan Rogers /* 0 */
22955ea8f2ccSIan Rogers },
22965ea8f2ccSIan Rogers {
22975ea8f2ccSIan Rogers .name = "{cpu/instructions/,cpu/branch-misses/}:Su",
22985ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
22995ea8f2ccSIan Rogers .check = test__leader_sample2,
23005ea8f2ccSIan Rogers /* 1 */
23015ea8f2ccSIan Rogers },
23025ea8f2ccSIan Rogers {
23035ea8f2ccSIan Rogers .name = "cpu/instructions/uDp",
23045ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23055ea8f2ccSIan Rogers .check = test__checkevent_pinned_modifier,
23065ea8f2ccSIan Rogers /* 2 */
23075ea8f2ccSIan Rogers },
23085ea8f2ccSIan Rogers {
23095ea8f2ccSIan Rogers .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:D",
23105ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23115ea8f2ccSIan Rogers .check = test__pinned_group,
23125ea8f2ccSIan Rogers /* 3 */
23135ea8f2ccSIan Rogers },
23145ea8f2ccSIan Rogers {
23155ea8f2ccSIan Rogers .name = "cpu/instructions/I",
23165ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23175ea8f2ccSIan Rogers .check = test__checkevent_exclude_idle_modifier,
23185ea8f2ccSIan Rogers /* 4 */
23195ea8f2ccSIan Rogers },
23205ea8f2ccSIan Rogers {
23215ea8f2ccSIan Rogers .name = "cpu/instructions/kIG",
23225ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23235ea8f2ccSIan Rogers .check = test__checkevent_exclude_idle_modifier_1,
23245ea8f2ccSIan Rogers /* 5 */
23255ea8f2ccSIan Rogers },
23265ea8f2ccSIan Rogers {
23275ea8f2ccSIan Rogers .name = "cpu/cycles/u",
23285ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23295ea8f2ccSIan Rogers .check = test__sym_event_slash,
23305ea8f2ccSIan Rogers /* 6 */
23315ea8f2ccSIan Rogers },
23325ea8f2ccSIan Rogers {
23335ea8f2ccSIan Rogers .name = "cpu/cycles/k",
23345ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23355ea8f2ccSIan Rogers .check = test__sym_event_dc,
23365ea8f2ccSIan Rogers /* 7 */
23375ea8f2ccSIan Rogers },
23385ea8f2ccSIan Rogers {
23395ea8f2ccSIan Rogers .name = "cpu/instructions/uep",
23405ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23415ea8f2ccSIan Rogers .check = test__checkevent_exclusive_modifier,
23425ea8f2ccSIan Rogers /* 8 */
23435ea8f2ccSIan Rogers },
23445ea8f2ccSIan Rogers {
23455ea8f2ccSIan Rogers .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:e",
23465ea8f2ccSIan Rogers .valid = test__pmu_cpu_valid,
23475ea8f2ccSIan Rogers .check = test__exclusive_group,
23485ea8f2ccSIan Rogers /* 9 */
23495ea8f2ccSIan Rogers },
2350e831f3ccSIan Rogers {
2351e831f3ccSIan Rogers .name = "cpu/cycles,name=name/",
2352e831f3ccSIan Rogers .valid = test__pmu_cpu_valid,
2353e831f3ccSIan Rogers .check = test__term_equal_term,
2354e831f3ccSIan Rogers /* 0 */
2355e831f3ccSIan Rogers },
23562aadca4bSIan Rogers {
23572aadca4bSIan Rogers .name = "cpu/cycles,name=l1d/",
23582aadca4bSIan Rogers .valid = test__pmu_cpu_valid,
23592aadca4bSIan Rogers .check = test__term_equal_legacy,
23602aadca4bSIan Rogers /* 1 */
23612aadca4bSIan Rogers },
2362945aea22SJiri Olsa };
2363945aea22SJiri Olsa
236423b6339bSArnaldo Carvalho de Melo struct terms_test {
2365945aea22SJiri Olsa const char *str;
2366945aea22SJiri Olsa int (*check)(struct list_head *terms);
2367945aea22SJiri Olsa };
2368945aea22SJiri Olsa
2369b58eca40SIan Rogers static const struct terms_test test__terms[] = {
2370945aea22SJiri Olsa [0] = {
2371204e7c49SRob Herring .str = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead",
2372945aea22SJiri Olsa .check = test__checkterms_simple,
2373945aea22SJiri Olsa },
2374945aea22SJiri Olsa };
2375945aea22SJiri Olsa
test_event(const struct evlist_test * e)23768252e791SIan Rogers static int test_event(const struct evlist_test *e)
2377945aea22SJiri Olsa {
2378a910e466SIan Rogers struct parse_events_error err;
237963503dbaSJiri Olsa struct evlist *evlist;
2380945aea22SJiri Olsa int ret;
2381945aea22SJiri Olsa
238216ddcfbfSJiri Olsa if (e->valid && !e->valid()) {
23837741e03eSIan Rogers pr_debug("... SKIP\n");
23847741e03eSIan Rogers return TEST_OK;
238516ddcfbfSJiri Olsa }
238616ddcfbfSJiri Olsa
23870f98b11cSJiri Olsa evlist = evlist__new();
23887741e03eSIan Rogers if (evlist == NULL) {
23897741e03eSIan Rogers pr_err("Failed allocation");
23907741e03eSIan Rogers return TEST_FAIL;
23917741e03eSIan Rogers }
239207eafd4eSIan Rogers parse_events_error__init(&err);
2393933ccf20SJiri Olsa ret = parse_events(evlist, e->name, &err);
2394945aea22SJiri Olsa if (ret) {
2395933ccf20SJiri Olsa pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2396933ccf20SJiri Olsa e->name, ret, err.str);
23976c191289SIan Rogers parse_events_error__print(&err, e->name);
23987741e03eSIan Rogers ret = TEST_FAIL;
2399aefde50aSIan Rogers if (err.str && strstr(err.str, "can't access trace events"))
24007741e03eSIan Rogers ret = TEST_SKIP;
24012d4352c0SArnaldo Carvalho de Melo } else {
24022d4352c0SArnaldo Carvalho de Melo ret = e->check(evlist);
2403945aea22SJiri Olsa }
240407eafd4eSIan Rogers parse_events_error__exit(&err);
2405c12995a5SJiri Olsa evlist__delete(evlist);
2406945aea22SJiri Olsa
2407945aea22SJiri Olsa return ret;
2408945aea22SJiri Olsa }
2409945aea22SJiri Olsa
test_event_fake_pmu(const char * str)2410b4a7276cSJohn Garry static int test_event_fake_pmu(const char *str)
2411b4a7276cSJohn Garry {
2412b4a7276cSJohn Garry struct parse_events_error err;
2413b4a7276cSJohn Garry struct evlist *evlist;
2414b4a7276cSJohn Garry int ret;
2415b4a7276cSJohn Garry
2416b4a7276cSJohn Garry evlist = evlist__new();
2417b4a7276cSJohn Garry if (!evlist)
2418b4a7276cSJohn Garry return -ENOMEM;
2419b4a7276cSJohn Garry
2420b4a7276cSJohn Garry parse_events_error__init(&err);
2421411ad22eSIan Rogers ret = __parse_events(evlist, str, /*pmu_filter=*/NULL, &err,
2422411ad22eSIan Rogers &perf_pmu__fake, /*warn_if_reordered=*/true);
2423b4a7276cSJohn Garry if (ret) {
2424b4a7276cSJohn Garry pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2425b4a7276cSJohn Garry str, ret, err.str);
2426b4a7276cSJohn Garry parse_events_error__print(&err, str);
2427b4a7276cSJohn Garry }
2428b4a7276cSJohn Garry
2429b4a7276cSJohn Garry parse_events_error__exit(&err);
2430b4a7276cSJohn Garry evlist__delete(evlist);
2431b4a7276cSJohn Garry
2432b4a7276cSJohn Garry return ret;
2433b4a7276cSJohn Garry }
2434b4a7276cSJohn Garry
combine_test_results(int existing,int latest)24357741e03eSIan Rogers static int combine_test_results(int existing, int latest)
24367741e03eSIan Rogers {
24377741e03eSIan Rogers if (existing == TEST_FAIL)
24387741e03eSIan Rogers return TEST_FAIL;
24397741e03eSIan Rogers if (existing == TEST_SKIP)
24407741e03eSIan Rogers return latest == TEST_OK ? TEST_SKIP : latest;
24417741e03eSIan Rogers return latest;
24427741e03eSIan Rogers }
24437741e03eSIan Rogers
test_events(const struct evlist_test * events,int cnt)24448252e791SIan Rogers static int test_events(const struct evlist_test *events, int cnt)
2445945aea22SJiri Olsa {
24467741e03eSIan Rogers int ret = TEST_OK;
2447945aea22SJiri Olsa
24488252e791SIan Rogers for (int i = 0; i < cnt; i++) {
24498252e791SIan Rogers const struct evlist_test *e = &events[i];
24507741e03eSIan Rogers int test_ret;
2451945aea22SJiri Olsa
24527741e03eSIan Rogers pr_debug("running test %d '%s'\n", i, e->name);
24537741e03eSIan Rogers test_ret = test_event(e);
24547741e03eSIan Rogers if (test_ret != TEST_OK) {
24557741e03eSIan Rogers pr_debug("Event test failure: test %d '%s'", i, e->name);
24567741e03eSIan Rogers ret = combine_test_results(ret, test_ret);
24577741e03eSIan Rogers }
2458945aea22SJiri Olsa }
2459945aea22SJiri Olsa
24607741e03eSIan Rogers return ret;
24617741e03eSIan Rogers }
24627741e03eSIan Rogers
test__events2(struct test_suite * test __maybe_unused,int subtest __maybe_unused)24637741e03eSIan Rogers static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
24647741e03eSIan Rogers {
24657741e03eSIan Rogers return test_events(test__events, ARRAY_SIZE(test__events));
2466945aea22SJiri Olsa }
2467945aea22SJiri Olsa
test_term(const struct terms_test * t)2468b58eca40SIan Rogers static int test_term(const struct terms_test *t)
2469945aea22SJiri Olsa {
2470c549aca5SDavid Ahern struct list_head terms;
2471945aea22SJiri Olsa int ret;
2472945aea22SJiri Olsa
2473c549aca5SDavid Ahern INIT_LIST_HEAD(&terms);
2474945aea22SJiri Olsa
2475edb217ffSIan Rogers ret = parse_events_terms(&terms, t->str, /*input=*/ NULL);
2476945aea22SJiri Olsa if (ret) {
2477945aea22SJiri Olsa pr_debug("failed to parse terms '%s', err %d\n",
2478945aea22SJiri Olsa t->str , ret);
2479945aea22SJiri Olsa return ret;
2480945aea22SJiri Olsa }
2481945aea22SJiri Olsa
2482c549aca5SDavid Ahern ret = t->check(&terms);
2483682dc24cSArnaldo Carvalho de Melo parse_events_terms__purge(&terms);
2484945aea22SJiri Olsa
2485945aea22SJiri Olsa return ret;
2486945aea22SJiri Olsa }
2487945aea22SJiri Olsa
test_terms(const struct terms_test * terms,int cnt)2488b58eca40SIan Rogers static int test_terms(const struct terms_test *terms, int cnt)
2489945aea22SJiri Olsa {
2490945aea22SJiri Olsa int ret = 0;
2491945aea22SJiri Olsa
2492b58eca40SIan Rogers for (int i = 0; i < cnt; i++) {
2493b58eca40SIan Rogers const struct terms_test *t = &terms[i];
2494945aea22SJiri Olsa
2495945aea22SJiri Olsa pr_debug("running test %d '%s'\n", i, t->str);
2496945aea22SJiri Olsa ret = test_term(t);
2497945aea22SJiri Olsa if (ret)
2498945aea22SJiri Olsa break;
2499945aea22SJiri Olsa }
2500945aea22SJiri Olsa
2501945aea22SJiri Olsa return ret;
2502945aea22SJiri Olsa }
2503945aea22SJiri Olsa
test__terms2(struct test_suite * test __maybe_unused,int subtest __maybe_unused)25047741e03eSIan Rogers static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
25057741e03eSIan Rogers {
25067741e03eSIan Rogers return test_terms(test__terms, ARRAY_SIZE(test__terms));
25077741e03eSIan Rogers }
25087741e03eSIan Rogers
test__pmu_events(struct test_suite * test __maybe_unused,int subtest __maybe_unused)25097741e03eSIan Rogers static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2510945aea22SJiri Olsa {
2511f24ebe80SIan Rogers struct perf_pmu *pmu = NULL;
25125a52817eSIan Rogers int ret = TEST_OK;
25135a52817eSIan Rogers
25141eaf496eSIan Rogers while ((pmu = perf_pmus__scan(pmu)) != NULL) {
2515945aea22SJiri Olsa struct stat st;
2516945aea22SJiri Olsa char path[PATH_MAX];
2517945aea22SJiri Olsa struct dirent *ent;
2518945aea22SJiri Olsa DIR *dir;
25195a52817eSIan Rogers int err;
2520945aea22SJiri Olsa
25215a52817eSIan Rogers snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
25225a52817eSIan Rogers sysfs__mountpoint(), pmu->name);
25237741e03eSIan Rogers
25245a52817eSIan Rogers err = stat(path, &st);
25255a52817eSIan Rogers if (err) {
25265a52817eSIan Rogers pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);
25275a52817eSIan Rogers continue;
2528945aea22SJiri Olsa }
2529945aea22SJiri Olsa
2530945aea22SJiri Olsa dir = opendir(path);
2531945aea22SJiri Olsa if (!dir) {
25327741e03eSIan Rogers pr_debug("can't open pmu event dir: %s\n", path);
25335a52817eSIan Rogers ret = combine_test_results(ret, TEST_SKIP);
25345a52817eSIan Rogers continue;
2535945aea22SJiri Olsa }
2536945aea22SJiri Olsa
25377741e03eSIan Rogers while ((ent = readdir(dir))) {
25388252e791SIan Rogers struct evlist_test e = { .name = NULL, };
25392e2bbc03SArnaldo Carvalho de Melo char name[2 * NAME_MAX + 1 + 12 + 3];
25407741e03eSIan Rogers int test_ret;
2541945aea22SJiri Olsa
254217a2634bSAndi Kleen /* Names containing . are special and cannot be used directly */
254317a2634bSAndi Kleen if (strchr(ent->d_name, '.'))
2544945aea22SJiri Olsa continue;
2545945aea22SJiri Olsa
25465a52817eSIan Rogers snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
2547945aea22SJiri Olsa
2548945aea22SJiri Olsa e.name = name;
2549945aea22SJiri Olsa e.check = test__checkevent_pmu_events;
2550945aea22SJiri Olsa
25517741e03eSIan Rogers test_ret = test_event(&e);
25527741e03eSIan Rogers if (test_ret != TEST_OK) {
25537741e03eSIan Rogers pr_debug("Test PMU event failed for '%s'", name);
25547741e03eSIan Rogers ret = combine_test_results(ret, test_ret);
25557741e03eSIan Rogers }
25565a52817eSIan Rogers
25575a52817eSIan Rogers if (!is_pmu_core(pmu->name))
25585a52817eSIan Rogers continue;
25595a52817eSIan Rogers
2560146edff3SIan Rogers /*
2561146edff3SIan Rogers * Names containing '-' are recognized as prefixes and suffixes
2562146edff3SIan Rogers * due to '-' being a legacy PMU separator. This fails when the
2563146edff3SIan Rogers * prefix or suffix collides with an existing legacy token. For
2564146edff3SIan Rogers * example, branch-brs has a prefix (branch) that collides with
2565146edff3SIan Rogers * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix
2566146edff3SIan Rogers * isn't expected after this. As event names in the config
2567146edff3SIan Rogers * slashes are allowed a '-' in the name we check this works
2568146edff3SIan Rogers * above.
2569146edff3SIan Rogers */
2570146edff3SIan Rogers if (strchr(ent->d_name, '-'))
2571146edff3SIan Rogers continue;
2572146edff3SIan Rogers
25735a52817eSIan Rogers snprintf(name, sizeof(name), "%s:u,%s/event=%s/u",
25745a52817eSIan Rogers ent->d_name, pmu->name, ent->d_name);
2575ffe59788SKan Liang e.name = name;
2576ffe59788SKan Liang e.check = test__checkevent_pmu_events_mix;
25777741e03eSIan Rogers test_ret = test_event(&e);
25787741e03eSIan Rogers if (test_ret != TEST_OK) {
25797741e03eSIan Rogers pr_debug("Test PMU event failed for '%s'", name);
25807741e03eSIan Rogers ret = combine_test_results(ret, test_ret);
25817741e03eSIan Rogers }
2582945aea22SJiri Olsa }
2583945aea22SJiri Olsa
2584945aea22SJiri Olsa closedir(dir);
25855a52817eSIan Rogers }
2586945aea22SJiri Olsa return ret;
2587945aea22SJiri Olsa }
2588945aea22SJiri Olsa
test__pmu_events2(struct test_suite * test __maybe_unused,int subtest __maybe_unused)25897741e03eSIan Rogers static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
25907741e03eSIan Rogers {
25917741e03eSIan Rogers return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
25927741e03eSIan Rogers }
25937741e03eSIan Rogers
test_alias(char ** event,char ** alias)2594c7a3828dSJin Yao static bool test_alias(char **event, char **alias)
2595c7a3828dSJin Yao {
2596c7a3828dSJin Yao char path[PATH_MAX];
2597c7a3828dSJin Yao DIR *dir;
2598c7a3828dSJin Yao struct dirent *dent;
2599c7a3828dSJin Yao const char *sysfs = sysfs__mountpoint();
2600c7a3828dSJin Yao char buf[128];
2601c7a3828dSJin Yao FILE *file;
2602c7a3828dSJin Yao
2603c7a3828dSJin Yao if (!sysfs)
2604c7a3828dSJin Yao return false;
2605c7a3828dSJin Yao
2606c7a3828dSJin Yao snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs);
2607c7a3828dSJin Yao dir = opendir(path);
2608c7a3828dSJin Yao if (!dir)
2609c7a3828dSJin Yao return false;
2610c7a3828dSJin Yao
2611c7a3828dSJin Yao while ((dent = readdir(dir))) {
2612c7a3828dSJin Yao if (!strcmp(dent->d_name, ".") ||
2613c7a3828dSJin Yao !strcmp(dent->d_name, ".."))
2614c7a3828dSJin Yao continue;
2615c7a3828dSJin Yao
2616c7a3828dSJin Yao snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias",
2617c7a3828dSJin Yao sysfs, dent->d_name);
2618c7a3828dSJin Yao
2619c7a3828dSJin Yao if (!file_available(path))
2620c7a3828dSJin Yao continue;
2621c7a3828dSJin Yao
2622c7a3828dSJin Yao file = fopen(path, "r");
2623c7a3828dSJin Yao if (!file)
2624c7a3828dSJin Yao continue;
2625c7a3828dSJin Yao
2626c7a3828dSJin Yao if (!fgets(buf, sizeof(buf), file)) {
2627c7a3828dSJin Yao fclose(file);
2628c7a3828dSJin Yao continue;
2629c7a3828dSJin Yao }
2630c7a3828dSJin Yao
2631c7a3828dSJin Yao /* Remove the last '\n' */
2632c7a3828dSJin Yao buf[strlen(buf) - 1] = 0;
2633c7a3828dSJin Yao
2634c7a3828dSJin Yao fclose(file);
2635c7a3828dSJin Yao *event = strdup(dent->d_name);
2636c7a3828dSJin Yao *alias = strdup(buf);
2637c7a3828dSJin Yao closedir(dir);
2638c7a3828dSJin Yao
2639c7a3828dSJin Yao if (*event == NULL || *alias == NULL) {
2640c7a3828dSJin Yao free(*event);
2641c7a3828dSJin Yao free(*alias);
2642c7a3828dSJin Yao return false;
2643c7a3828dSJin Yao }
2644c7a3828dSJin Yao
2645c7a3828dSJin Yao return true;
2646c7a3828dSJin Yao }
2647c7a3828dSJin Yao
2648c7a3828dSJin Yao closedir(dir);
2649c7a3828dSJin Yao return false;
2650c7a3828dSJin Yao }
2651c7a3828dSJin Yao
test__checkevent_pmu_events_alias(struct evlist * evlist)2652c7a3828dSJin Yao static int test__checkevent_pmu_events_alias(struct evlist *evlist)
2653c7a3828dSJin Yao {
2654c7a3828dSJin Yao struct evsel *evsel1 = evlist__first(evlist);
2655c7a3828dSJin Yao struct evsel *evsel2 = evlist__last(evlist);
2656c7a3828dSJin Yao
2657c7a3828dSJin Yao TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type);
2658c7a3828dSJin Yao TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config);
26597741e03eSIan Rogers return TEST_OK;
2660c7a3828dSJin Yao }
2661c7a3828dSJin Yao
test__pmu_events_alias(char * event,char * alias)26627741e03eSIan Rogers static int test__pmu_events_alias(char *event, char *alias)
2663c7a3828dSJin Yao {
26648252e791SIan Rogers struct evlist_test e = { .name = NULL, };
2665c7a3828dSJin Yao char name[2 * NAME_MAX + 20];
2666c7a3828dSJin Yao
2667c7a3828dSJin Yao snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/",
2668c7a3828dSJin Yao event, alias);
2669c7a3828dSJin Yao
2670c7a3828dSJin Yao e.name = name;
2671c7a3828dSJin Yao e.check = test__checkevent_pmu_events_alias;
2672c7a3828dSJin Yao return test_event(&e);
2673c7a3828dSJin Yao }
2674c7a3828dSJin Yao
test__alias(struct test_suite * test __maybe_unused,int subtest __maybe_unused)26757741e03eSIan Rogers static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
26767741e03eSIan Rogers {
26777741e03eSIan Rogers char *event, *alias;
26787741e03eSIan Rogers int ret;
26797741e03eSIan Rogers
26807741e03eSIan Rogers if (!test_alias(&event, &alias))
26817741e03eSIan Rogers return TEST_SKIP;
26827741e03eSIan Rogers
26837741e03eSIan Rogers ret = test__pmu_events_alias(event, alias);
26847741e03eSIan Rogers
26857741e03eSIan Rogers free(event);
26867741e03eSIan Rogers free(alias);
26877741e03eSIan Rogers return ret;
26887741e03eSIan Rogers }
26897741e03eSIan Rogers
test__pmu_events_alias2(struct test_suite * test __maybe_unused,int subtest __maybe_unused)26907741e03eSIan Rogers static int test__pmu_events_alias2(struct test_suite *test __maybe_unused,
26917741e03eSIan Rogers int subtest __maybe_unused)
2692b4a7276cSJohn Garry {
2693b4a7276cSJohn Garry static const char events[][30] = {
2694b4a7276cSJohn Garry "event-hyphen",
2695b4a7276cSJohn Garry "event-two-hyph",
2696b4a7276cSJohn Garry };
26977741e03eSIan Rogers int ret = TEST_OK;
2698b4a7276cSJohn Garry
26997741e03eSIan Rogers for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) {
27007741e03eSIan Rogers int test_ret = test_event_fake_pmu(&events[i][0]);
27017741e03eSIan Rogers
27027741e03eSIan Rogers if (test_ret != TEST_OK) {
27037741e03eSIan Rogers pr_debug("check_parse_fake %s failed\n", &events[i][0]);
27047741e03eSIan Rogers ret = combine_test_results(ret, test_ret);
2705b4a7276cSJohn Garry }
2706b4a7276cSJohn Garry }
2707b4a7276cSJohn Garry
2708b4a7276cSJohn Garry return ret;
2709b4a7276cSJohn Garry }
2710b4a7276cSJohn Garry
27117741e03eSIan Rogers static struct test_case tests__parse_events[] = {
27127741e03eSIan Rogers TEST_CASE_REASON("Test event parsing",
27137741e03eSIan Rogers events2,
27147741e03eSIan Rogers "permissions"),
27157741e03eSIan Rogers TEST_CASE_REASON("Parsing of all PMU events from sysfs",
27167741e03eSIan Rogers pmu_events,
27177741e03eSIan Rogers "permissions"),
27187741e03eSIan Rogers TEST_CASE_REASON("Parsing of given PMU events from sysfs",
27197741e03eSIan Rogers pmu_events2,
27207741e03eSIan Rogers "permissions"),
27217741e03eSIan Rogers TEST_CASE_REASON("Parsing of aliased events from sysfs", alias,
27227741e03eSIan Rogers "no aliases in sysfs"),
27237741e03eSIan Rogers TEST_CASE("Parsing of aliased events", pmu_events_alias2),
27247741e03eSIan Rogers TEST_CASE("Parsing of terms (event modifiers)", terms2),
27257741e03eSIan Rogers { .name = NULL, }
27267741e03eSIan Rogers };
2727945aea22SJiri Olsa
27287741e03eSIan Rogers struct test_suite suite__parse_events = {
27297741e03eSIan Rogers .desc = "Parse event definition strings",
27307741e03eSIan Rogers .test_cases = tests__parse_events,
27317741e03eSIan Rogers };
2732