Skip to content

Commit c3a8f85

Browse files
James-A-Clarkacmel
authored andcommitted
perf test: Add mechanism for skipping attr tests on auxiliary vector values
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 <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a8f2619 commit c3a8f85

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

tools/perf/tests/attr.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import optparse
99
import tempfile
1010
import logging
11+
import re
1112
import shutil
13+
import subprocess
1214

1315
try:
1416
import configparser
@@ -134,6 +136,8 @@ def diff(self, other):
134136
# 'arch' - architecture specific test (optional)
135137
# comma separated list, ! at the beginning
136138
# negates it.
139+
# 'auxv' - Truthy statement that is evaled in the scope of the auxv map. When false,
140+
# the test is skipped. For example 'auxv["AT_HWCAP"] == 10'. (optional)
137141
#
138142
# [eventX:base]
139143
# - one or multiple instances in file
@@ -164,6 +168,7 @@ def __init__(self, path, options):
164168
except:
165169
self.arch = ''
166170

171+
self.auxv = parser.get('config', 'auxv', fallback=None)
167172
self.expect = {}
168173
self.result = {}
169174
log.debug(" loading expected events");
@@ -175,7 +180,28 @@ def is_event(self, name):
175180
else:
176181
return True
177182

178-
def skip_test(self, myarch):
183+
def skip_test_auxv(self):
184+
def new_auxv(a, pattern):
185+
items = list(filter(None, pattern.split(a)))
186+
# AT_HWCAP is hex but doesn't have a prefix, so special case it
187+
if items[0] == "AT_HWCAP":
188+
value = int(items[-1], 16)
189+
else:
190+
try:
191+
value = int(items[-1], 0)
192+
except:
193+
value = items[-1]
194+
return (items[0], value)
195+
196+
if not self.auxv:
197+
return False
198+
auxv = subprocess.check_output("LD_SHOW_AUXV=1 sleep 0", shell=True) \
199+
.decode(sys.stdout.encoding)
200+
pattern = re.compile(r"[: ]+")
201+
auxv = dict([new_auxv(a, pattern) for a in auxv.splitlines()])
202+
return not eval(self.auxv)
203+
204+
def skip_test_arch(self, myarch):
179205
# If architecture not set always run test
180206
if self.arch == '':
181207
# log.warning("test for arch %s is ok" % myarch)
@@ -225,9 +251,12 @@ def load_events(self, path, events):
225251
def run_cmd(self, tempdir):
226252
junk1, junk2, junk3, junk4, myarch = (os.uname())
227253

228-
if self.skip_test(myarch):
254+
if self.skip_test_arch(myarch):
229255
raise Notest(self, myarch)
230256

257+
if self.skip_test_auxv():
258+
raise Notest(self, "auxv skip")
259+
231260
cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir,
232261
self.perf, self.command, tempdir, self.args)
233262
ret = os.WEXITSTATUS(os.system(cmd))

0 commit comments

Comments
 (0)