From patchwork Tue Dec 13 11:47:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp69555wrn; Tue, 13 Dec 2022 03:54:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UmBHlZVsJ6FciFRTXDZmDWFCJbTcAlXp7+o5lYvdSP2JxsnT6/kOgBACW6L6pUCmSa1RB X-Received: by 2002:a17:903:234f:b0:189:9676:28a1 with SMTP id c15-20020a170903234f00b00189967628a1mr27101485plh.35.1670932499366; Tue, 13 Dec 2022 03:54:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670932499; cv=none; d=google.com; s=arc-20160816; b=bIeD51eIWsOxYnawlpepi/QpUGb0gIxH9BKYuv88HaU4JcjsU+M5sw0YqjIoe1swEY v+3U7LtYskSjrmI5Cjmiee+WwYzqUOQj9In5ztGDp/+4uI9JdFBJ3hLmtc1g+hXyib89 n6IN0ropGZIDiRHidHNelmyV9qhZePvgbEmw8RLXd99wutPQ3RPVFPwDSrssvNOrnpua N/043NP8CnVt9rh5ScQkWlTwndZndCFlq24zID9lRT/1v+quLKVO0N21macP951LhPKj KsmKn0pO2R0bPkPCkoqHW9qVHpIIjZ38HrqQ3XxGYuFZ+5OeQfjZb3LiZeFuC7Vb1e65 rjDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zhHUBOgpfIW1k/emvz/2sOKCRYuYfTs+EYHdYNeIzxo=; b=trzm6o60K+eYOtVH5dyf+zZ20t/nIJa/5uRTdKueRn7KtUX1Nk0q2f5NzgXusjmdZv FMMvT4HFEFeywTPLqUCGkLbPLQASsON72mCwkWOo0wbtzAuU7rs96lcGZdMStNeNAlm4 +HoyP8BDxvM/inmZvdiUPtv5LZPCsla9t/Q4GPnZ/PLR4HYsY4GCEXzdmh3Ipk4xvvyW +GS8bUl4P63ZZjkajxYshmbIFxhiAU6MyuLjmA/7bCwqAAK+ZIEFEmnNZB+POdr5k4BO Q3cx8vEUE/C2PiPF9Cf8BYpYevsHoSVBmGK4d67EG/Dqr+sGHlehOjJm7Ug2B92YbQeL Wh1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij22-20020a170902ab5600b001895e356f00si11657099plb.152.2022.12.13.03.54.46; Tue, 13 Dec 2022 03:54:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235386AbiLMLug (ORCPT + 99 others); Tue, 13 Dec 2022 06:50:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235299AbiLMLu2 (ORCPT ); Tue, 13 Dec 2022 06:50:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0023A1057F; Tue, 13 Dec 2022 03:50:26 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D4FE1688; Tue, 13 Dec 2022 03:51:07 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2A2993F5A1; Tue, 13 Dec 2022 03:50:25 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 2/4] perf test: Add mechanism for skipping attr tests on auxiliary vector values Date: Tue, 13 Dec 2022 11:47:37 +0000 Message-Id: <20221213114739.2312862-3-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221213114739.2312862-1-james.clark@arm.com> References: <20221213114739.2312862-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752099716373645505?= X-GMAIL-MSGID: =?utf-8?q?1752099716373645505?= This can be used to skip tests or provide different test values on different platforms. For example to run a test only where Arm SVE is present add this to the config section: auxv = auxv["AT_HWCAP"] & 0x200000 == 0x200000 The value is a freeform Python expression that is evaled in the context of a map called "auxv" that contains the decoded auxiliary vector. Signed-off-by: James Clark --- tools/perf/tests/attr.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/attr.py b/tools/perf/tests/attr.py index cf40df472918..eceb6d022141 100644 --- a/tools/perf/tests/attr.py +++ b/tools/perf/tests/attr.py @@ -8,7 +8,9 @@ import glob import optparse import tempfile import logging +import re import shutil +import subprocess try: import configparser @@ -134,6 +136,8 @@ class Event(dict): # 'arch' - architecture specific test (optional) # comma separated list, ! at the beginning # negates it. +# 'auxv' - Truthy statement that is evaled in the scope of the auxv map. When false, +# the test is skipped. For example 'auxv["AT_HWCAP"] == 10'. (optional) # # [eventX:base] # - one or multiple instances in file @@ -164,6 +168,7 @@ class Test(object): except: self.arch = '' + self.auxv = parser.get('config', 'auxv', fallback=None) self.expect = {} self.result = {} log.debug(" loading expected events"); @@ -175,7 +180,28 @@ class Test(object): else: return True - def skip_test(self, myarch): + def skip_test_auxv(self): + def new_auxv(a, pattern): + items = list(filter(None, pattern.split(a))) + # AT_HWCAP is hex but doesn't have a prefix, so special case it + if items[0] == "AT_HWCAP": + value = int(items[-1], 16) + else: + try: + value = int(items[-1], 0) + except: + value = items[-1] + return (items[0], value) + + if not self.auxv: + return False + auxv = subprocess.check_output("LD_SHOW_AUXV=1 sleep 0", shell=True) \ + .decode(sys.stdout.encoding) + pattern = re.compile(r"[: ]+") + auxv = dict([new_auxv(a, pattern) for a in auxv.splitlines()]) + return not eval(self.auxv) + + def skip_test_arch(self, myarch): # If architecture not set always run test if self.arch == '': # log.warning("test for arch %s is ok" % myarch) @@ -225,9 +251,12 @@ class Test(object): def run_cmd(self, tempdir): junk1, junk2, junk3, junk4, myarch = (os.uname()) - if self.skip_test(myarch): + if self.skip_test_arch(myarch): raise Notest(self, myarch) + if self.skip_test_auxv(): + raise Notest(self, "auxv skip") + cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir, self.perf, self.command, tempdir, self.args) ret = os.WEXITSTATUS(os.system(cmd))