Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <james.clark@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221213114739.2312862-3-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

James Clark and committed by
Arnaldo Carvalho de Melo
c3a8f853 a8f26192

+31 -2
+31 -2
tools/perf/tests/attr.py
··· 8 8 import optparse 9 9 import tempfile 10 10 import logging 11 + import re 11 12 import shutil 13 + import subprocess 12 14 13 15 try: 14 16 import configparser ··· 136 134 # 'arch' - architecture specific test (optional) 137 135 # comma separated list, ! at the beginning 138 136 # negates it. 137 + # 'auxv' - Truthy statement that is evaled in the scope of the auxv map. When false, 138 + # the test is skipped. For example 'auxv["AT_HWCAP"] == 10'. (optional) 139 139 # 140 140 # [eventX:base] 141 141 # - one or multiple instances in file ··· 168 164 except: 169 165 self.arch = '' 170 166 167 + self.auxv = parser.get('config', 'auxv', fallback=None) 171 168 self.expect = {} 172 169 self.result = {} 173 170 log.debug(" loading expected events"); ··· 180 175 else: 181 176 return True 182 177 183 - def skip_test(self, myarch): 178 + def skip_test_auxv(self): 179 + def new_auxv(a, pattern): 180 + items = list(filter(None, pattern.split(a))) 181 + # AT_HWCAP is hex but doesn't have a prefix, so special case it 182 + if items[0] == "AT_HWCAP": 183 + value = int(items[-1], 16) 184 + else: 185 + try: 186 + value = int(items[-1], 0) 187 + except: 188 + value = items[-1] 189 + return (items[0], value) 190 + 191 + if not self.auxv: 192 + return False 193 + auxv = subprocess.check_output("LD_SHOW_AUXV=1 sleep 0", shell=True) \ 194 + .decode(sys.stdout.encoding) 195 + pattern = re.compile(r"[: ]+") 196 + auxv = dict([new_auxv(a, pattern) for a in auxv.splitlines()]) 197 + return not eval(self.auxv) 198 + 199 + def skip_test_arch(self, myarch): 184 200 # If architecture not set always run test 185 201 if self.arch == '': 186 202 # log.warning("test for arch %s is ok" % myarch) ··· 251 225 def run_cmd(self, tempdir): 252 226 junk1, junk2, junk3, junk4, myarch = (os.uname()) 253 227 254 - if self.skip_test(myarch): 228 + if self.skip_test_arch(myarch): 255 229 raise Notest(self, myarch) 230 + 231 + if self.skip_test_auxv(): 232 + raise Notest(self, "auxv skip") 256 233 257 234 cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir, 258 235 self.perf, self.command, tempdir, self.args)