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 count_pfm_events(struct perf_evlist *evlist)
17 struct perf_evsel *evsel;
20 perf_evlist__for_each_entry(evlist, evsel) {
26 static int test__pfm_events(struct test_suite *test __maybe_unused,
27 int subtest __maybe_unused)
29 struct evlist *evlist;
41 .events = "instructions",
45 .events = "instructions,cycles",
49 .events = "stereolab",
53 .events = "instructions,instructions",
57 .events = "stereolab,instructions",
61 .events = "instructions,stereolab",
66 for (i = 0; i < ARRAY_SIZE(table); i++) {
67 evlist = evlist__new();
72 parse_libpfm_events_option(&opt,
75 TEST_ASSERT_EQUAL(table[i].events,
76 count_pfm_events(&evlist->core),
78 TEST_ASSERT_EQUAL(table[i].events,
79 evlist__nr_groups(evlist),
82 evlist__delete(evlist);
87 static int test__pfm_group(struct test_suite *test __maybe_unused,
88 int subtest __maybe_unused)
90 struct evlist *evlist;
104 .events = "{instructions}",
109 .events = "{instructions},{}",
114 .events = "{},{instructions}",
119 .events = "{instructions},{instructions}",
124 .events = "{instructions,cycles},{instructions,cycles}",
129 .events = "{stereolab}",
135 "{instructions,cycles},{instructions,stereolab}",
140 .events = "instructions}",
145 .events = "{{instructions}}",
151 for (i = 0; i < ARRAY_SIZE(table); i++) {
152 evlist = evlist__new();
157 parse_libpfm_events_option(&opt,
160 TEST_ASSERT_EQUAL(table[i].events,
161 count_pfm_events(&evlist->core),
163 TEST_ASSERT_EQUAL(table[i].events,
164 evlist__nr_groups(evlist),
167 evlist__delete(evlist);
172 static int test__pfm_events(struct test_suite *test __maybe_unused,
173 int subtest __maybe_unused)
178 static int test__pfm_group(struct test_suite *test __maybe_unused,
179 int subtest __maybe_unused)
185 static struct test_case pfm_tests[] = {
186 TEST_CASE_REASON("test of individual --pfm-events", pfm_events, "not compiled in"),
187 TEST_CASE_REASON("test groups of --pfm-events", pfm_group, "not compiled in"),
191 struct test_suite suite__pfm = {
192 .desc = "Test libpfm4 support",
193 .test_cases = pfm_tests,