1# Copyright 2016 The Chromium 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 5"""A handler and functions to check whether bisect is supported.""" 6 7import re 8 9from dashboard import namespaced_stored_object 10 11# A set of suites for which we can't do performance bisects. 12_UNBISECTABLE_SUITES = [ 13 'arc-perf-test', 14 'browser_tests', 15 'content_browsertests', 16 'sizes', 17 'v8', 18] 19 20# The bisect bot map stored in datastore is expected to be 21# a dict mapping master names to [perf bot, bisect bot] pairs. 22# If a master name is not in the dict, bisect isn't supported. 23BISECT_BOT_MAP_KEY = 'bisect_bot_map' 24 25 26def IsValidTestForBisect(test_path): 27 """Checks whether a test is valid for bisect.""" 28 if not test_path: 29 return False 30 path_parts = test_path.split('/') 31 if len(path_parts) < 3: 32 return False 33 if not _MasterNameIsWhitelisted(path_parts[0]): 34 return False 35 if path_parts[2] in _UNBISECTABLE_SUITES: 36 return False 37 if test_path.endswith('/ref') or test_path.endswith('_ref'): 38 return False 39 return True 40 41 42def _MasterNameIsWhitelisted(master_name): 43 """Checks whether a master name is acceptable by checking a whitelist.""" 44 bisect_bot_map = namespaced_stored_object.Get(BISECT_BOT_MAP_KEY) 45 if not bisect_bot_map: 46 return True # If there's no list available, all names are OK. 47 whitelisted_masters = list(bisect_bot_map) 48 return master_name in whitelisted_masters 49 50 51def IsValidRevisionForBisect(revision): 52 """Checks whether a revision looks like a valid revision for bisect.""" 53 return _IsGitHash(revision) or re.match(r'^[0-9]{5,7}$', str(revision)) 54 55 56def _IsGitHash(revision): 57 """Checks whether the input looks like a SHA1 hash.""" 58 return re.match(r'[a-fA-F0-9]{40}$', str(revision)) 59