1 // SPDX-License-Identifier: GPL-2.0
3 * Test support for libpfm4 event encodings.
5 * Copyright 2020 Google LLC.
8 #include "util/debug.h"
9 #include "util/evlist.h"
12 #include <linux/kernel.h>
15 static int test__pfm_events(void);
16 static int test__pfm_group(void);
22 } pfm_testcase_table[] = {
25 .func = test__pfm_events,
26 .desc = "test of individual --pfm-events",
29 .func = test__pfm_group,
30 .desc = "test groups of --pfm-events",
36 static int count_pfm_events(struct perf_evlist *evlist)
38 struct perf_evsel *evsel;
41 perf_evlist__for_each_entry(evlist, evsel) {
47 static int test__pfm_events(void)
49 struct evlist *evlist;
61 .events = "instructions",
65 .events = "instructions,cycles",
69 .events = "stereolab",
73 .events = "instructions,instructions",
77 .events = "stereolab,instructions",
81 .events = "instructions,stereolab",
86 for (i = 0; i < ARRAY_SIZE(table); i++) {
87 evlist = evlist__new();
92 parse_libpfm_events_option(&opt,
95 TEST_ASSERT_EQUAL(table[i].events,
96 count_pfm_events(&evlist->core),
98 TEST_ASSERT_EQUAL(table[i].events,
99 evlist->core.nr_groups,
102 evlist__delete(evlist);
107 static int test__pfm_group(void)
109 struct evlist *evlist;
123 .events = "{instructions}",
128 .events = "{instructions},{}",
133 .events = "{},{instructions}",
138 .events = "{instructions},{instructions}",
143 .events = "{instructions,cycles},{instructions,cycles}",
148 .events = "{stereolab}",
154 "{instructions,cycles},{instructions,stereolab}",
159 .events = "instructions}",
164 .events = "{{instructions}}",
170 for (i = 0; i < ARRAY_SIZE(table); i++) {
171 evlist = evlist__new();
176 parse_libpfm_events_option(&opt,
179 TEST_ASSERT_EQUAL(table[i].events,
180 count_pfm_events(&evlist->core),
182 TEST_ASSERT_EQUAL(table[i].events,
183 evlist->core.nr_groups,
186 evlist__delete(evlist);
192 const char *test__pfm_subtest_get_desc(int i)
194 if (i < 0 || i >= (int)ARRAY_SIZE(pfm_testcase_table))
196 return pfm_testcase_table[i].desc;
199 int test__pfm_subtest_get_nr(void)
201 return (int)ARRAY_SIZE(pfm_testcase_table);
204 int test__pfm(struct test *test __maybe_unused, int i __maybe_unused)
207 if (i < 0 || i >= (int)ARRAY_SIZE(pfm_testcase_table))
209 return pfm_testcase_table[i].func();