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 kernel versions

The first two version numbers are used since that is where the ABI
changes happen, so seems to be the most useful for now.

'Until' is exclusive and 'since' is inclusive so that the same version
number can be used to mark a point where the change comes into effect.

This allows keeping the tests in a state where new tests will also pass
on older kernels if the existence of a new feature isn't explicitly
broadcast by the kernel. For example extended user regs are currently
discovered by trial and error calls to perf_event_open.

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-4-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
ee26adf6 c3a8f853

+27 -1
+27 -1
tools/perf/tests/attr.py
··· 6 6 import sys 7 7 import glob 8 8 import optparse 9 + import platform 9 10 import tempfile 10 11 import logging 11 12 import re ··· 126 125 if not data_equal(self[t], other[t]): 127 126 log.warning("expected %s=%s, got %s" % (t, self[t], other[t])) 128 127 128 + def parse_version(version): 129 + if not version: 130 + return None 131 + return [int(v) for v in version.split(".")[0:2]] 132 + 129 133 # Test file description needs to have following sections: 130 134 # [config] 131 135 # - just single instance in file ··· 144 138 # negates it. 145 139 # 'auxv' - Truthy statement that is evaled in the scope of the auxv map. When false, 146 140 # the test is skipped. For example 'auxv["AT_HWCAP"] == 10'. (optional) 147 - # 141 + # 'kernel_since' - Inclusive kernel version from which the test will start running. Only the 142 + # first two values are supported, for example "6.1" (optional) 143 + # 'kernel_until' - Exclusive kernel version from which the test will stop running. (optional) 148 144 # [eventX:base] 149 145 # - one or multiple instances in file 150 146 # - expected values assignments ··· 177 169 self.arch = '' 178 170 179 171 self.auxv = parser.get('config', 'auxv', fallback=None) 172 + self.kernel_since = parse_version(parser.get('config', 'kernel_since', fallback=None)) 173 + self.kernel_until = parse_version(parser.get('config', 'kernel_until', fallback=None)) 180 174 self.expect = {} 181 175 self.result = {} 182 176 log.debug(" loading expected events"); ··· 189 179 return False 190 180 else: 191 181 return True 182 + 183 + def skip_test_kernel_since(self): 184 + if not self.kernel_since: 185 + return False 186 + return not self.kernel_since <= parse_version(platform.release()) 187 + 188 + def skip_test_kernel_until(self): 189 + if not self.kernel_until: 190 + return False 191 + return not parse_version(platform.release()) < self.kernel_until 192 192 193 193 def skip_test_auxv(self): 194 194 def new_auxv(a, pattern): ··· 276 256 277 257 if self.skip_test_auxv(): 278 258 raise Notest(self, "auxv skip") 259 + 260 + if self.skip_test_kernel_since(): 261 + raise Notest(self, "old kernel skip") 262 + 263 + if self.skip_test_kernel_until(): 264 + raise Notest(self, "new kernel skip") 279 265 280 266 cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir, 281 267 self.perf, self.command, tempdir, self.args)