Commit 34bacc95 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tests: Factor check_parse_id function

Separating the generic part of check_parse_id function,
so it can be used in following changes for the new test.

Committer notes:

Fix this error:

  tests/pmu-events.c:413:40: error: missing field 'idx' initializer [-Werror,-Wmissing-field-initializers]
        struct parse_events_error error = { 0 };
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200602214741.1218986-4-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 387ad33f
...@@ -390,9 +390,8 @@ static bool is_number(const char *str) ...@@ -390,9 +390,8 @@ static bool is_number(const char *str)
return errno == 0 && end_ptr != str; return errno == 0 && end_ptr != str;
} }
static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe) static int check_parse_id(const char *id, struct parse_events_error *error)
{ {
struct parse_events_error error;
struct evlist *evlist; struct evlist *evlist;
int ret; int ret;
...@@ -401,8 +400,18 @@ static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe) ...@@ -401,8 +400,18 @@ static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe)
return 0; return 0;
evlist = evlist__new(); evlist = evlist__new();
memset(&error, 0, sizeof(error)); if (!evlist)
ret = parse_events(evlist, id, &error); return -ENOMEM;
ret = parse_events(evlist, id, error);
evlist__delete(evlist);
return ret;
}
static int check_parse_cpu(const char *id, bool same_cpu, struct pmu_event *pe)
{
struct parse_events_error error = { .idx = 0, };
int ret = check_parse_id(id, &error);
if (ret && same_cpu) { if (ret && same_cpu) {
pr_warning("Parse event failed metric '%s' id '%s' expr '%s'\n", pr_warning("Parse event failed metric '%s' id '%s' expr '%s'\n",
pe->metric_name, id, pe->metric_expr); pe->metric_name, id, pe->metric_expr);
...@@ -413,7 +422,6 @@ static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe) ...@@ -413,7 +422,6 @@ static int check_parse_id(const char *id, bool same_cpu, struct pmu_event *pe)
id, pe->metric_name, pe->metric_expr); id, pe->metric_name, pe->metric_expr);
ret = 0; ret = 0;
} }
evlist__delete(evlist);
free(error.str); free(error.str);
free(error.help); free(error.help);
free(error.first_str); free(error.first_str);
...@@ -474,7 +482,7 @@ static int test_parsing(void) ...@@ -474,7 +482,7 @@ static int test_parsing(void)
expr__add_id(&ctx, strdup(cur->key), k++); expr__add_id(&ctx, strdup(cur->key), k++);
hashmap__for_each_entry((&ctx.ids), cur, bkt) { hashmap__for_each_entry((&ctx.ids), cur, bkt) {
if (check_parse_id(cur->key, map == cpus_map, if (check_parse_cpu(cur->key, map == cpus_map,
pe)) pe))
ret++; ret++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment