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
,
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}",
160 for (i
= 0; i
< ARRAY_SIZE(table
); i
++) {
161 evlist
= evlist__new();
166 parse_libpfm_events_option(&opt
,
169 TEST_ASSERT_EQUAL(table
[i
].events
,
170 count_pfm_events(&evlist
->core
),
172 TEST_ASSERT_EQUAL(table
[i
].events
,
176 evlist__delete(evlist
);
182 const char *test__pfm_subtest_get_desc(int i
)
184 if (i
< 0 || i
>= (int)ARRAY_SIZE(pfm_testcase_table
))
186 return pfm_testcase_table
[i
].desc
;
189 int test__pfm_subtest_get_nr(void)
191 return (int)ARRAY_SIZE(pfm_testcase_table
);
194 int test__pfm(struct test
*test __maybe_unused
, int i __maybe_unused
)
197 if (i
< 0 || i
>= (int)ARRAY_SIZE(pfm_testcase_table
))
199 return pfm_testcase_table
[i
].func();