Re: [PATCH v3 12/46] perf test: Test more sysfs events

From: Ian Rogers
Date: Tue May 02 2023 - 11:30:15 EST


On Tue, May 2, 2023 at 8:16 AM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Tue, May 2, 2023 at 3:27 AM Ravi Bangoria <ravi.bangoria@xxxxxxx> wrote:
> >
> > > @@ -2225,74 +2226,82 @@ static int test_pmu(void)
> > >
> > > static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
> > > {
> > > - struct stat st;
> > > - char path[PATH_MAX];
> > > - struct dirent *ent;
> > > - DIR *dir;
> > > - int ret;
> > > + struct perf_pmu *pmu;
> > > + int ret = TEST_OK;
> > >
> > > - if (!test_pmu())
> > > - return TEST_SKIP;
> > > + perf_pmus__for_each_pmu(pmu) {
> >
> > 'pmus' list might be empty and, if so, we need to fill it first with:
> >
> > if (list_empty(&pmus))
> > perf_pmu__scan(NULL);
> >
> > before iterating over it. Other option is to add this code to
> > perf_pmus__for_each_pmu() macro itself.
> >
> > With that, the test fails for me:
> >
> > $ sudo ./perf test 6
> > 6: Parse event definition strings :
> > 6.1: Test event parsing : Ok
> > 6.2: Test parsing of "hybrid" CPU events : Skip (not hybrid)
> > 6.3: Parsing of all PMU events from sysfs : FAILED!
> >
> > > + struct stat st;
> > > + char path[PATH_MAX];
> > > + struct dirent *ent;
> > > + DIR *dir;
> > > + int err;
> > >
> > > - snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
> > > - sysfs__mountpoint());
> > > + snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
> > > + sysfs__mountpoint(), pmu->name);
> > >
> > > - ret = stat(path, &st);
> > > - if (ret) {
> > > - pr_debug("omitting PMU cpu events tests: %s\n", path);
> > > - return TEST_OK;
> > > - }
> > > + err = stat(path, &st);
> > > + if (err) {
> > > + pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);
> > > + ret = combine_test_results(ret, TEST_SKIP);
> >
> > combine_test_results(ret, TEST_OK); probably? Since many pmus don't expose
> > events via sysfs.
>
> Thanks Ravi! The following looks to address the issues and I'll add it to v4.
>
> '''
> diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
> index 35b35a5c795c..2ff61ee8f970 100644
> --- a/tools/perf/tests/parse-events.c
> +++ b/tools/perf/tests/parse-events.c
> @@ -559,7 +559,8 @@ static int test__checkevent_pmu_events(struct
> evlist *evlist)
> struct evsel *evsel = evlist__first(evlist);
>
> TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
> - TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
> + TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||
> + strncmp(evsel->pmu_name, "cpu/", 4));

This should be strcmp(evsel->pmu_name, "cpu"). Or we could drop the
assert. I'll try to keep what's covered currently by the test while
extending the PMUs.

Thanks,
Ian

> TEST_ASSERT_VAL("wrong exclude_user",
> !evsel->core.attr.exclude_user);
> TEST_ASSERT_VAL("wrong exclude_kernel",
> @@ -2229,6 +2230,9 @@ static int test__pmu_events(struct test_suite
> *test __maybe_unused, int subtes
> t
> struct perf_pmu *pmu;
> int ret = TEST_OK;
>
> + if (list_empty(&pmus))
> + perf_pmu__scan(NULL);
> +
> perf_pmus__for_each_pmu(pmu) {
> struct stat st;
> char path[PATH_MAX];
> @@ -2242,7 +2246,6 @@ static int test__pmu_events(struct test_suite
> *test __maybe_unused, int subtes
> t
> err = stat(path, &st);
> if (err) {
> pr_debug("skipping PMU %s events tests: %s\n",
> pmu->name, path);
> - ret = combine_test_results(ret, TEST_SKIP);
> continue;
> }
> '''