Skip to content

Commit 07d2b82

Browse files
captain5050acmel
authored andcommitted
perf test parse-events: Test complex name has required event format
test__checkevent_complex_name will use an "event" format which if not present, such as with a placeholder PMU, will cause test failures. Skip the test in this case to avoid failures in restricted environments. Add perf_pmu__has_format utility as a general PMU utility. Fixes: 628eaa4 ("perf pmus: Add placeholder core PMU") Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Thomas Richter <tmricht@linux.ibm.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.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: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20230706183705.601412-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 34bc65d commit 07d2b82

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

tools/perf/tests/parse-events.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,16 @@ static bool test__pmu_cpu_valid(void)
16311631
return !!perf_pmus__find("cpu");
16321632
}
16331633

1634+
static bool test__pmu_cpu_event_valid(void)
1635+
{
1636+
struct perf_pmu *pmu = perf_pmus__find("cpu");
1637+
1638+
if (!pmu)
1639+
return false;
1640+
1641+
return perf_pmu__has_format(pmu, "event");
1642+
}
1643+
16341644
static bool test__intel_pt_valid(void)
16351645
{
16361646
return !!perf_pmus__find("intel_pt");
@@ -2179,7 +2189,7 @@ static const struct evlist_test test__events_pmu[] = {
21792189
},
21802190
{
21812191
.name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
2182-
.valid = test__pmu_cpu_valid,
2192+
.valid = test__pmu_cpu_event_valid,
21832193
.check = test__checkevent_complex_name,
21842194
/* 3 */
21852195
},

tools/perf/util/pmu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,17 @@ void perf_pmu__del_formats(struct list_head *formats)
14401440
}
14411441
}
14421442

1443+
bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name)
1444+
{
1445+
struct perf_pmu_format *format;
1446+
1447+
list_for_each_entry(format, &pmu->format, list) {
1448+
if (!strcmp(format->name, name))
1449+
return true;
1450+
}
1451+
return false;
1452+
}
1453+
14431454
bool is_pmu_core(const char *name)
14441455
{
14451456
return !strcmp(name, "cpu") || !strcmp(name, "cpum_cf") || is_sysfs_pmu_core(name);

tools/perf/util/pmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ int perf_pmu__new_format(struct list_head *list, char *name,
234234
void perf_pmu__set_format(unsigned long *bits, long from, long to);
235235
int perf_pmu__format_parse(int dirfd, struct list_head *head);
236236
void perf_pmu__del_formats(struct list_head *formats);
237+
bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name);
237238

238239
bool is_pmu_core(const char *name);
239240
bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu);

0 commit comments

Comments
 (0)