Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp914545pxb; Mon, 16 Aug 2021 22:23:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKlQXwsVuyeUya5wCJe6muJONFdxQC20XVsdW9otOsI+EQkDOUj6xoxUv44XGt0F0vW4QA X-Received: by 2002:a92:cc86:: with SMTP id x6mr1249108ilo.119.1629177829424; Mon, 16 Aug 2021 22:23:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629177829; cv=none; d=google.com; s=arc-20160816; b=u8D9KQirjpVJAiJOzPSSzGDUCrZlgoCSboYMYLEvfr13y9T8OxoTHsHJfqg2lUD87f jPXWIdzbJ1mG7OqFaeXDtvt9PpyKnAtE91l2gL2a47YskHRNB5cef082Iek88LXHyhoP GHUq+9rzz9bT7HeE0jZzVlM7AZu5BFt4nQT8C44I8Zfyi3CIUmC9p1EtyfCKSMGxS8t4 AI1b5eW2jL/WhyrmeSJjaq4mH8uAfCqbj1+5hzRRnSz50irQR/KuhLp+MPvNwZDHByxL BAo8j0+Rv+d3NLFytdz8vnGC112WP6C27O5pHYILWc3vbbtWcD78GZ1QN/glPs3ddaS6 EUPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=jOtVuOzQw8dhUu9JAwjiMP7A5LolZUvmvbbxHFollDQ=; b=NudzR2wb4LX34HVE7cjc842yE3svsZxKnqHN4/vN8uCID0ZDUYEKPxNQP7YfkGvPZd iLW/S2ZmJc4Y00a5SFUP721AYhDMHpTZvl1AsdhZxwzvM9NAiE3dCB6gaJ5sMX1qTPLd cuZVtNcaR8XvqyDfpgIUz8sQxJyxl7EzrFUeWDhCYrd2hiQ3LsjwmZ5zJafHVyyS5dS1 sp9TF1ETkJOE1ZtnxgKvEbuDeNxzAw6HwkfHC9ZMGnIdk1D4P7YvVoeK30mdqjIeNGf7 +pgvAPRofy28UmIACP9C8t2FYESztXVsVzvAlDM0UsNzL5eCR8DZjLzRqlZQc/uu0a7v LZYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z41si1235574jah.89.2021.08.16.22.23.38; Mon, 16 Aug 2021 22:23:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238174AbhHQFWI (ORCPT + 99 others); Tue, 17 Aug 2021 01:22:08 -0400 Received: from mga09.intel.com ([134.134.136.24]:50476 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237960AbhHQFVv (ORCPT ); Tue, 17 Aug 2021 01:21:51 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10078"; a="215996588" X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="215996588" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2021 22:21:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,328,1620716400"; d="scan'208";a="462255110" Received: from kbl-ppc.sh.intel.com ([10.239.159.163]) by orsmga007.jf.intel.com with ESMTP; 16 Aug 2021 22:21:15 -0700 From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: 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, Jin Yao Subject: [PATCH v5 2/2] perf tests: Test for PMU alias Date: Tue, 17 Aug 2021 13:19:33 +0800 Message-Id: <20210817051933.16978-3-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210817051933.16978-1-yao.jin@linux.intel.com> References: <20210817051933.16978-1-yao.jin@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Jin Yao Reviewed-by: Andi Kleen --- 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