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