1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 #include "parse-events.h"
8 static int do_test(enum tool_pmu_event ev
, bool with_pmu
)
10 struct evlist
*evlist
= evlist__new();
12 struct parse_events_error err
;
18 pr_err("evlist allocation failed\n");
23 snprintf(str
, sizeof(str
), "tool/%s/", tool_pmu__event_to_str(ev
));
25 snprintf(str
, sizeof(str
), "%s", tool_pmu__event_to_str(ev
));
27 parse_events_error__init(&err
);
28 ret
= parse_events(evlist
, str
, &err
);
30 if (tool_pmu__skip_event(tool_pmu__event_to_str(ev
))) {
35 pr_debug("FAILED %s:%d failed to parse event '%s', err %d\n",
36 __FILE__
, __LINE__
, str
, ret
);
37 parse_events_error__print(&err
, str
);
43 if (with_pmu
? (evlist
->core
.nr_entries
!= 1) : (evlist
->core
.nr_entries
< 1)) {
44 pr_debug("FAILED %s:%d Unexpected number of events for '%s' of %d\n",
45 __FILE__
, __LINE__
, str
, evlist
->core
.nr_entries
);
50 evlist__for_each_entry(evlist
, evsel
) {
51 if (perf_pmu__is_tool(evsel
->pmu
)) {
52 if (evsel
->core
.attr
.config
!= ev
) {
53 pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %d\n",
54 __FILE__
, __LINE__
, str
, evsel
->core
.attr
.config
, ev
);
62 if (!found
&& !tool_pmu__skip_event(tool_pmu__event_to_str(ev
))) {
63 pr_debug("FAILED %s:%d Didn't find tool event '%s' in parsed evsels\n",
64 __FILE__
, __LINE__
, str
);
69 parse_events_error__exit(&err
);
70 evlist__delete(evlist
);
74 static int test__tool_pmu_without_pmu(struct test_suite
*test __maybe_unused
,
75 int subtest __maybe_unused
)
79 tool_pmu__for_each_event(i
) {
80 int ret
= do_test(i
, /*with_pmu=*/false);
88 static int test__tool_pmu_with_pmu(struct test_suite
*test __maybe_unused
,
89 int subtest __maybe_unused
)
93 tool_pmu__for_each_event(i
) {
94 int ret
= do_test(i
, /*with_pmu=*/true);
102 static struct test_case tests__tool_pmu
[] = {
103 TEST_CASE("Parsing without PMU name", tool_pmu_without_pmu
),
104 TEST_CASE("Parsing with PMU name", tool_pmu_with_pmu
),
108 struct test_suite suite__tool_pmu
= {
110 .test_cases
= tests__tool_pmu
,