drm/nouveau: fix kernel-doc comments
[drm/drm-misc.git] / tools / perf / tests / evsel-roundtrip-name.c
blob1922cac13a24530c1d6a3e483e87122d50f83f54
1 // SPDX-License-Identifier: GPL-2.0
2 #include "evlist.h"
3 #include "evsel.h"
4 #include "parse-events.h"
5 #include "tests.h"
6 #include "debug.h"
7 #include <linux/kernel.h>
9 static int perf_evsel__roundtrip_cache_name_test(void)
11 int ret = TEST_OK;
13 for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
14 for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
15 /* skip invalid cache type */
16 if (!evsel__is_cache_op_valid(type, op))
17 continue;
19 for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) {
20 char name[128];
21 struct evlist *evlist = evlist__new();
22 struct evsel *evsel;
23 int err;
25 if (evlist == NULL) {
26 pr_debug("Failed to alloc evlist");
27 return TEST_FAIL;
29 __evsel__hw_cache_type_op_res_name(type, op, res,
30 name, sizeof(name));
32 err = parse_event(evlist, name);
33 if (err) {
34 pr_debug("Failure to parse cache event '%s' possibly as PMUs don't support it",
35 name);
36 evlist__delete(evlist);
37 continue;
39 evlist__for_each_entry(evlist, evsel) {
40 if (!evsel__name_is(evsel, name)) {
41 pr_debug("%s != %s\n", evsel__name(evsel), name);
42 ret = TEST_FAIL;
45 evlist__delete(evlist);
49 return ret;
52 static int perf_evsel__name_array_test(const char *const names[], int nr_names)
54 int ret = TEST_OK;
56 for (int i = 0; i < nr_names; ++i) {
57 struct evlist *evlist = evlist__new();
58 struct evsel *evsel;
59 int err;
61 if (evlist == NULL) {
62 pr_debug("Failed to alloc evlist");
63 return TEST_FAIL;
65 err = parse_event(evlist, names[i]);
66 if (err) {
67 pr_debug("failed to parse event '%s', err %d\n",
68 names[i], err);
69 evlist__delete(evlist);
70 ret = TEST_FAIL;
71 continue;
73 evlist__for_each_entry(evlist, evsel) {
74 if (!evsel__name_is(evsel, names[i])) {
75 pr_debug("%s != %s\n", evsel__name(evsel), names[i]);
76 ret = TEST_FAIL;
79 evlist__delete(evlist);
81 return ret;
84 static int test__perf_evsel__roundtrip_name_test(struct test_suite *test __maybe_unused,
85 int subtest __maybe_unused)
87 int err = 0, ret = TEST_OK;
89 err = perf_evsel__name_array_test(evsel__hw_names, PERF_COUNT_HW_MAX);
90 if (err)
91 ret = err;
93 err = perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1);
94 if (err)
95 ret = err;
97 err = perf_evsel__roundtrip_cache_name_test();
98 if (err)
99 ret = err;
101 return ret;
104 DEFINE_SUITE("Roundtrip evsel->name", perf_evsel__roundtrip_name_test);