From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DF83C433EF for ; Fri, 3 Sep 2021 11:40:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E123F610CC for ; Fri, 3 Sep 2021 11:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349313AbhICLlb (ORCPT ); Fri, 3 Sep 2021 07:41:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234758AbhICLl2 (ORCPT ); Fri, 3 Sep 2021 07:41:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C013A60EE3; Fri, 3 Sep 2021 11:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630669229; bh=0GxAcpJ1IV/AldhMsFNwb31fY3HVlcvl5EjEi4BO5wU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OGL/VpgZS7U971JVYneGisVWgts5MLsobCV8nYrUJYTpu9/uv0HY+5SsUxuRKNE3/ qKmD4j7siBCa79EpMMK+d0qa3u8liRKWLCc2ENr1xniHnOT7Oh08eY1HcKSfjrphnu ogshKjyhcQhoEzJA+01Luxnr1RciB3no1CLrrFvHMyNvVb418Jdn/ujOBpe2PcgVmc RKkqaCKln0p+PQnTMtWuQRJcSomuzfTgHOO9BzZ0J/mgQl+1HV3aLT7XepPtlcCE4q Rkp0AcWOP4kzkLeZ0Hg1vUcrVKIjqxPB4LD0+tdxid7idpNy2q/A9zRfyH7Wmxd/i2 ZYKwLrm/3BUWA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id C6C594007E; Fri, 3 Sep 2021 08:40:25 -0300 (-03) Date: Fri, 3 Sep 2021 08:40:25 -0300 From: Arnaldo Carvalho de Melo To: Jin Yao Cc: jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, Linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, rickyman7@gmail.com, john.garry@huawei.com Subject: Re: [PATCH v7 2/2] perf tests: Test for PMU alias Message-ID: References: <20210902065955.1299-1-yao.jin@linux.intel.com> <20210902065955.1299-3-yao.jin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210902065955.1299-3-yao.jin@linux.intel.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Sep 02, 2021 at 02:59:55PM +0800, Jin Yao escreveu: > A perf uncore PMU may have two PMU names, a real name and an alias > name. Add one test case to verify the real name and alias name having > the same effect. > > Iterate the sysfs to get one event which has an alias and create > evlist by adding two evsels. Evsel1 is created by event and evsel2 > is created by alias. > > Test asserts: > evsel1->core.attr.type == evsel2->core.attr.type > evsel1->core.attr.config == evsel2->core.attr.config Thanks, applied. - Arnaldo > Signed-off-by: Jin Yao > Reviewed-by: Andi Kleen > --- > v7: > - No change. > > v6: > - No change. > > v5: > - No change. > > v4: > - Rebase to perf/core. > > v3: > - Use fgets to read alias string from sysfs. > - Resource cleanup. > > v2: > - New in v2. > > tools/perf/tests/parse-events.c | 92 +++++++++++++++++++++++++++++++++ > 1 file changed, 92 insertions(+) > > diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c > index 8d4866739255..fd3556cc9ad4 100644 > --- a/tools/perf/tests/parse-events.c > +++ b/tools/perf/tests/parse-events.c > @@ -9,6 +9,7 @@ > #include "pmu-hybrid.h" > #include > #include > +#include "fncache.h" > #include > #include > #include > @@ -2194,9 +2195,91 @@ static int test_pmu_events(void) > return ret; > } > > +static bool test_alias(char **event, char **alias) > +{ > + char path[PATH_MAX]; > + DIR *dir; > + struct dirent *dent; > + const char *sysfs = sysfs__mountpoint(); > + char buf[128]; > + FILE *file; > + > + if (!sysfs) > + return false; > + > + snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs); > + dir = opendir(path); > + if (!dir) > + return false; > + > + while ((dent = readdir(dir))) { > + if (!strcmp(dent->d_name, ".") || > + !strcmp(dent->d_name, "..")) > + continue; > + > + snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias", > + sysfs, dent->d_name); > + > + if (!file_available(path)) > + continue; > + > + file = fopen(path, "r"); > + if (!file) > + continue; > + > + if (!fgets(buf, sizeof(buf), file)) { > + fclose(file); > + continue; > + } > + > + /* Remove the last '\n' */ > + buf[strlen(buf) - 1] = 0; > + > + fclose(file); > + *event = strdup(dent->d_name); > + *alias = strdup(buf); > + closedir(dir); > + > + if (*event == NULL || *alias == NULL) { > + free(*event); > + free(*alias); > + return false; > + } > + > + return true; > + } > + > + closedir(dir); > + return false; > +} > + > +static int test__checkevent_pmu_events_alias(struct evlist *evlist) > +{ > + struct evsel *evsel1 = evlist__first(evlist); > + struct evsel *evsel2 = evlist__last(evlist); > + > + TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type); > + TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config); > + return 0; > +} > + > +static int test_pmu_events_alias(char *event, char *alias) > +{ > + struct evlist_test e = { .id = 0, }; > + char name[2 * NAME_MAX + 20]; > + > + snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/", > + event, alias); > + > + e.name = name; > + e.check = test__checkevent_pmu_events_alias; > + return test_event(&e); > +} > + > int test__parse_events(struct test *test __maybe_unused, int subtest __maybe_unused) > { > int ret1, ret2 = 0; > + char *event, *alias; > > #define TEST_EVENTS(tests) \ > do { \ > @@ -2221,6 +2304,15 @@ do { \ > return ret; > } > > + if (test_alias(&event, &alias)) { > + int ret = test_pmu_events_alias(event, alias); > + > + free(event); > + free(alias); > + if (ret) > + return ret; > + } > + > ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms)); > if (!ret2) > ret2 = ret1; > -- > 2.17.1 -- - Arnaldo