1 # Copyright (c) 2013 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.
5 """Top-level presubmit script for auto-bisect.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API.
15 # Paths to bisect config files relative to this script.
18 os
.path
.join(os
.path
.pardir
, 'run-perf-test.cfg'),
21 def CheckChangeOnUpload(input_api
, output_api
):
22 return _CommonChecks(input_api
, output_api
)
25 def CheckChangeOnCommit(input_api
, output_api
):
26 return _CommonChecks(input_api
, output_api
)
29 def _CommonChecks(input_api
, output_api
):
30 """Does all presubmit checks for auto-bisect."""
32 results
.extend(_CheckAllConfigFiles(input_api
, output_api
))
33 results
.extend(_RunUnitTests(input_api
, output_api
))
34 results
.extend(_RunPyLint(input_api
, output_api
))
38 def _CheckAllConfigFiles(input_api
, output_api
):
39 """Checks all bisect config files and returns a list of presubmit results."""
41 script_path
= input_api
.PresubmitLocalPath()
42 for config_file
in CONFIG_FILES
:
43 file_path
= os
.path
.join(script_path
, config_file
)
44 results
.extend(_CheckConfigFile(file_path
, output_api
))
48 def _CheckConfigFile(file_path
, output_api
):
49 """Checks one bisect config file and returns a list of presubmit results."""
51 config_file
= imp
.load_source('config', file_path
)
53 warning
= 'Failed to read config file %s: %s' % (file_path
, str(e
))
54 return [output_api
.PresubmitError(warning
, items
=[file_path
])]
56 if not hasattr(config_file
, 'config'):
57 warning
= 'Config file has no "config" global variable: %s' % str(e
)
58 return [output_api
.PresubmitError(warning
, items
=[file_path
])]
60 if type(config_file
.config
) is not dict:
61 warning
= 'Config file "config" global variable is not dict: %s' % str(e
)
62 return [output_api
.PresubmitError(warning
, items
=[file_path
])]
64 for k
, v
in config_file
.config
.iteritems():
66 warning
= 'Non-empty value in config dict: %s: %s' % (repr(k
), repr(v
))
67 warning
+= ('\nThe bisection config file should only contain a config '
68 'dict with empty fields. Changes to this file should not '
70 return [output_api
.PresubmitError(warning
, items
=[file_path
])]
75 def _RunUnitTests(input_api
, output_api
):
76 """Runs unit tests for auto-bisect."""
77 repo_root
= input_api
.change
.RepositoryRoot()
78 auto_bisect_dir
= os
.path
.join(repo_root
, 'tools', 'auto_bisect')
79 test_runner
= os
.path
.join(auto_bisect_dir
, 'run_tests')
80 return_code
= subprocess
.call(['python', test_runner
])
82 message
= 'Auto-bisect unit tests did not all pass.'
83 return [output_api
.PresubmitError(message
)]
87 def _RunPyLint(input_api
, output_api
):
88 """Runs unit tests for auto-bisect."""
89 telemetry_path
= os
.path
.join(
90 input_api
.PresubmitLocalPath(), os
.path
.pardir
, 'telemetry')
91 mock_path
= os
.path
.join(
92 input_api
.PresubmitLocalPath(), os
.path
.pardir
, os
.path
.pardir
,
93 'third_party', 'pymock')
97 tests
= input_api
.canned_checks
.GetPylint(
98 input_api
, output_api
, disabled_warnings
=disabled_warnings
,
99 extra_paths_list
=[telemetry_path
, mock_path
])
100 return input_api
.RunTests(tests
)