Lines Matching +full:self +full:- +full:test
1 # SPDX-License-Identifier: GPL-2.0
36 def __init__(self, test, msg): argument
37 self.msg = msg
38 self.test = test
39 def getMsg(self): argument
40 return '\'%s\' - %s' % (self.test.path, self.msg)
43 def __init__(self, test, arch): argument
44 self.arch = arch
45 self.test = test
46 def getMsg(self): argument
47 return '[%s] \'%s\'' % (self.arch, self.test.path)
50 def __init__(self, test): argument
51 self.test = test
52 def getMsg(self): argument
53 return '\'%s\'' % self.test.path
96 def add(self, data): argument
99 self[key] = val
101 def __init__(self, name, data, base): argument
103 self.name = name;
104 self.group = ''
105 self.add(base)
106 self.add(data)
108 def equal(self, other): argument
110 log.debug(" [%s] %s %s" % (t, self[t], other[t]));
111 if t not in self or t not in other:
113 if not data_equal(self[t], other[t]):
117 def optional(self): argument
118 if 'optional' in self and self['optional'] == '1':
122 def diff(self, other): argument
124 if t not in self or t not in other:
126 if not data_equal(self[t], other[t]):
127 log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
134 # Test file description needs to have following sections:
136 # - just single instance in file
137 # - needs to specify:
138 # 'command' - perf command name
139 # 'args' - special command arguments
140 # 'ret' - Skip test if Perf doesn't exit with this value (0 by default)
141 # 'test_ret'- If set to 'true', fail test instead of skipping for 'ret' argument
142 # 'arch' - architecture specific test (optional)
145 # 'auxv' - Truthy statement that is evaled in the scope of the auxv map. When false,
146 # the test is skipped. For example 'auxv["AT_HWCAP"] == 10'. (optional)
147 # 'kernel_since' - Inclusive kernel version from which the test will start running. Only the
149 # 'kernel_until' - Exclusive kernel version from which the test will stop running. (optional)
151 # - one or multiple instances in file
152 # - expected values assignments
153 class Test(object): class
154 def __init__(self, path, options): argument
160 self.path = path
161 self.test_dir = options.test_dir
162 self.perf = options.perf
163 self.command = parser.get('config', 'command')
164 self.args = parser.get('config', 'args')
167 self.ret = parser.get('config', 'ret')
169 self.ret = 0
171 self.test_ret = parser.getboolean('config', 'test_ret', fallback=False)
174 self.arch = parser.get('config', 'arch')
175 log.warning("test limitation '%s'" % self.arch)
177 self.arch = ''
179 self.auxv = parser.get('config', 'auxv', fallback=None)
180 self.kernel_since = parse_version(parser.get('config', 'kernel_since', fallback=None))
181 self.kernel_until = parse_version(parser.get('config', 'kernel_until', fallback=None))
182 self.expect = {}
183 self.result = {}
185 self.load_events(path, self.expect)
187 def is_event(self, name): argument
188 if name.find("event") == -1:
193 def skip_test_kernel_since(self): argument
194 if not self.kernel_since:
196 return not self.kernel_since <= parse_version(platform.release())
198 def skip_test_kernel_until(self): argument
199 if not self.kernel_until:
201 return not parse_version(platform.release()) < self.kernel_until
203 def skip_test_auxv(self): argument
208 value = int(items[-1], 16)
211 value = int(items[-1], 0)
213 value = items[-1]
216 if not self.auxv:
222 return not eval(self.auxv)
224 def skip_test_arch(self, myarch): argument
225 # If architecture not set always run test
226 if self.arch == '':
227 # log.warning("test for arch %s is ok" % myarch)
231 arch_list = self.arch.split(',')
238 # log.warning("test for %s arch is %s" % (arch_item, myarch))
244 # log.warning("test for architecture '%s' current '%s'" % (arch_item, myarch))
249 def load_events(self, path, events): argument
256 for section in filter(self.is_event, parser_event.sections()):
265 parser_base.read(self.test_dir + '/' + base)
271 def run_cmd(self, tempdir): argument
274 if self.skip_test_arch(myarch):
275 raise Notest(self, myarch)
277 if self.skip_test_auxv():
278 raise Notest(self, "auxv skip")
280 if self.skip_test_kernel_since():
281 raise Notest(self, "old kernel skip")
283 if self.skip_test_kernel_until():
284 raise Notest(self, "new kernel skip")
286 cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir,
287 self.perf, self.command, tempdir, self.args)
290 log.info(" '%s' ret '%s', expected '%s'" % (cmd, str(ret), str(self.ret)))
292 if not data_equal(str(ret), str(self.ret)):
293 if self.test_ret:
294 raise Fail(self, "Perf exit code failure")
296 raise Unsup(self)
298 def compare(self, expect, result): argument
313 log.debug(" ->OK")
315 log.debug(" ->FAIL");
319 # we did not any matching event - fail
328 raise Fail(self, 'match failure');
343 raise Fail(self, 'group failure')
350 def resolve_groups(self, events): argument
353 if group_fd == '-1':
362 def run(self): argument
366 # run the test script
367 self.run_cmd(tempdir);
369 # load events expectation for the test
372 self.load_events(f, self.result);
375 self.resolve_groups(self.expect);
376 self.resolve_groups(self.result);
378 # do the expectation - results matching - both ways
379 self.compare(self.expect, self.result)
380 self.compare(self.result, self.expect)
388 for f in glob.glob(options.test_dir + '/' + options.test):
390 Test(f, options).run()
407 log = logging.getLogger('test')
416 -d dir # tests dir
417 -p path # perf binary
418 -t test # single test
419 -v # verbose level
425 parser.add_option("-t", "--test",
426 action="store", type="string", dest="test")
427 parser.add_option("-d", "--test-dir",
429 parser.add_option("-p", "--perf",
431 parser.add_option("-v", "--verbose",
437 return -1
442 print('FAILED no -d option specified')
443 sys.exit(-1)
445 if not options.test:
446 options.test = 'test*'
453 sys.exit(-1)