1# Copyright 2018 the V8 project authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from collections import defaultdict 6import fnmatch 7 8from . import base 9 10 11class StatusFileFilterProc(base.TestProcFilter): 12 """Filters tests by outcomes from status file. 13 14 Status file has to be loaded before using this function. 15 16 Args: 17 slow_tests_mode: What to do with slow tests. 18 pass_fail_tests_mode: What to do with pass or fail tests. 19 20 Mode options: 21 None (default): don't skip 22 "skip": skip if slow/pass_fail 23 "run": skip if not slow/pass_fail 24 """ 25 26 def __init__(self, slow_tests_mode, pass_fail_tests_mode): 27 super(StatusFileFilterProc, self).__init__() 28 self._slow_tests_mode = slow_tests_mode 29 self._pass_fail_tests_mode = pass_fail_tests_mode 30 31 def _filter(self, test): 32 return ( 33 test.do_skip or 34 self._skip_slow(test.is_slow) or 35 self._skip_pass_fail(test.is_pass_or_fail) 36 ) 37 38 def _skip_slow(self, is_slow): 39 return ( 40 (self._slow_tests_mode == 'run' and not is_slow) or 41 (self._slow_tests_mode == 'skip' and is_slow) 42 ) 43 44 def _skip_pass_fail(self, is_pass_fail): 45 return ( 46 (self._pass_fail_tests_mode == 'run' and not is_pass_fail) or 47 (self._pass_fail_tests_mode == 'skip' and is_pass_fail) 48 ) 49 50 51class NameFilterProc(base.TestProcFilter): 52 """Filters tests based on command-line arguments. 53 54 args can be a glob: asterisks in any position of the name 55 represent zero or more characters. Without asterisks, only exact matches 56 will be used with the exeption of the test-suite name as argument. 57 """ 58 def __init__(self, args): 59 super(NameFilterProc, self).__init__() 60 61 self._globs = defaultdict(list) 62 self._exact_matches = defaultdict(dict) 63 for a in args: 64 argpath = a.split('/') 65 suitename = argpath[0] 66 path = '/'.join(argpath[1:]) or '*' 67 if '*' in path: 68 self._globs[suitename].append(path) 69 else: 70 self._exact_matches[suitename][path] = True 71 72 for s, globs in self._globs.iteritems(): 73 if not globs or '*' in globs: 74 self._globs[s] = ['*'] 75 76 def _filter(self, test): 77 globs = self._globs.get(test.suite.name, []) 78 for g in globs: 79 if g == '*': return False 80 if fnmatch.fnmatch(test.path, g): 81 return False 82 exact_matches = self._exact_matches.get(test.suite.name, {}) 83 return test.path not in exact_matches 84