summaryrefslogtreecommitdiff
path: root/tools/perf/tests
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-09-02 02:39:49 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-09-11 16:26:36 +0300
commit0d3f0e6f94ef58d5532e23b6d153b0890cf0014c (patch)
tree6c6abd222bb01b1ec83c12c53ebe2b85aeb13887 /tools/perf/tests
parent727adeed06e82915841e121762eb329881ae0107 (diff)
downloadlinux-0d3f0e6f94ef58d5532e23b6d153b0890cf0014c.tar.xz
perf parse-events: Introduce 'struct parse_events_terms'
parse_events_terms() existed in function names but was passed a 'struct list_head'. As many parse_events functions take an evsel_config list as well as a parse_event_term list, and the naming head_terms and head_config is inconsistent, there's a potential to switch the lists and get errors. Introduce a 'struct parse_events_terms', that just wraps a list_head, to avoid this. Add the regular init/exit functions and transition the code to use them. Reviewed-by: James Clark <james.clark@arm.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20230901233949.2930562-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests')
-rw-r--r--tools/perf/tests/parse-events.c12
-rw-r--r--tools/perf/tests/pmu.c23
2 files changed, 21 insertions, 14 deletions
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index d47f1f871164..93796e885cef 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -771,12 +771,12 @@ static int test__checkevent_pmu_events_mix(struct evlist *evlist)
return TEST_OK;
}
-static int test__checkterms_simple(struct list_head *terms)
+static int test__checkterms_simple(struct parse_events_terms *terms)
{
struct parse_events_term *term;
/* config=10 */
- term = list_entry(terms->next, struct parse_events_term, list);
+ term = list_entry(terms->terms.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term",
term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
TEST_ASSERT_VAL("wrong type val",
@@ -2363,7 +2363,7 @@ static const struct evlist_test test__events_pmu[] = {
struct terms_test {
const char *str;
- int (*check)(struct list_head *terms);
+ int (*check)(struct parse_events_terms *terms);
};
static const struct terms_test test__terms[] = {
@@ -2467,11 +2467,11 @@ static int test__events2(struct test_suite *test __maybe_unused, int subtest __m
static int test_term(const struct terms_test *t)
{
- struct list_head terms;
+ struct parse_events_terms terms;
int ret;
- INIT_LIST_HEAD(&terms);
+ parse_events_terms__init(&terms);
ret = parse_events_terms(&terms, t->str, /*input=*/ NULL);
if (ret) {
pr_debug("failed to parse terms '%s', err %d\n",
@@ -2480,7 +2480,7 @@ static int test_term(const struct terms_test *t)
}
ret = t->check(&terms);
- parse_events_terms__purge(&terms);
+ parse_events_terms__exit(&terms);
return ret;
}
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
index eb60e5f66859..8f18127d876a 100644
--- a/tools/perf/tests/pmu.c
+++ b/tools/perf/tests/pmu.c
@@ -128,30 +128,35 @@ static int test_format_dir_put(char *dir)
return system(buf);
}
-static struct list_head *test_terms_list(void)
+static void add_test_terms(struct parse_events_terms *terms)
{
- static LIST_HEAD(terms);
unsigned int i;
- for (i = 0; i < ARRAY_SIZE(test_terms); i++)
- list_add_tail(&test_terms[i].list, &terms);
+ for (i = 0; i < ARRAY_SIZE(test_terms); i++) {
+ struct parse_events_term *clone;
- return &terms;
+ parse_events_term__clone(&clone, &test_terms[i]);
+ list_add_tail(&clone->list, &terms->terms);
+ }
}
static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
char dir[PATH_MAX];
char *format;
- struct list_head *terms = test_terms_list();
+ struct parse_events_terms terms;
struct perf_event_attr attr;
struct perf_pmu *pmu;
int fd;
int ret;
+ parse_events_terms__init(&terms);
+ add_test_terms(&terms);
pmu = zalloc(sizeof(*pmu));
- if (!pmu)
+ if (!pmu) {
+ parse_events_terms__exit(&terms);
return -ENOMEM;
+ }
INIT_LIST_HEAD(&pmu->format);
INIT_LIST_HEAD(&pmu->aliases);
@@ -159,6 +164,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe
format = test_format_dir_get(dir, sizeof(dir));
if (!format) {
free(pmu);
+ parse_events_terms__exit(&terms);
return -EINVAL;
}
@@ -175,7 +181,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe
if (ret)
goto out;
- ret = perf_pmu__config_terms(pmu, &attr, terms, /*zero=*/false, /*err=*/NULL);
+ ret = perf_pmu__config_terms(pmu, &attr, &terms, /*zero=*/false, /*err=*/NULL);
if (ret)
goto out;
@@ -191,6 +197,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe
out:
test_format_dir_put(format);
perf_pmu__delete(pmu);
+ parse_events_terms__exit(&terms);
return ret;
}