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

From: Ravi Bangoria
Date: Tue May 02 2023 - 06:29:31 EST


> @@ -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.