Unify Help/Feedback/Credits menus.
[chromium-blink-merge.git] / tools / run-bisect-manual-test.py
blob2631a86a48fc72b6c8432447b897e06a5b18689c
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Run Manual Test Bisect Tool
8 An example usage:
9 tools/run-bisect-manual-test.py -g 201281 -b 201290
11 On Linux platform, follow the instructions in this document
12 https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
13 to setup the sandbox manually before running the script. Otherwise the script
14 fails to launch Chrome and exits with an error.
16 This script serves a similar function to bisect-builds.py, except it uses
17 the bisect_perf_regression.py. This means that that it can obtain builds of
18 Chromium for revisions where builds aren't available in cloud storage.
19 """
21 import os
22 import subprocess
23 import sys
25 CROS_BOARD_ENV = 'BISECT_CROS_BOARD'
26 CROS_IP_ENV = 'BISECT_CROS_IP'
27 _TOOLS_DIR = os.path.abspath(os.path.dirname(__file__))
28 _BISECT_SCRIPT_PATH = os.path.join(
29 _TOOLS_DIR, 'auto_bisect', 'bisect_perf_regression.py')
31 sys.path.append(os.path.join(_TOOLS_DIR, 'telemetry'))
32 from telemetry.core import browser_options
35 def _RunBisectionScript(options):
36 """Attempts to execute the bisect script (bisect_perf_regression.py).
38 Args:
39 options: The configuration options to pass to the bisect script.
41 Returns:
42 An exit code; 0 for success, 1 for failure.
43 """
44 script_path = os.path.join(options.working_directory,
45 'bisect', 'src', 'tools','bisect-manual-test.py')
46 abs_script_path = os.path.abspath(script_path)
48 test_command = ('python %s --browser=%s --chrome-root=.' %
49 (abs_script_path, options.browser_type))
51 cmd = ['python', _BISECT_SCRIPT_PATH,
52 '-c', test_command,
53 '-g', options.good_revision,
54 '-b', options.bad_revision,
55 '-m', 'manual_test/manual_test',
56 '-r', '1',
57 '--working_directory', options.working_directory,
58 '--build_preference', 'ninja',
59 '--no_custom_deps',
60 '--builder_type', options.builder_type]
62 if options.extra_src:
63 cmd.extend(['--extra_src', options.extra_src])
65 if 'cros' in options.browser_type:
66 cmd.extend(['--target_platform', 'cros'])
68 if os.environ[CROS_BOARD_ENV] and os.environ[CROS_IP_ENV]:
69 cmd.extend(['--cros_board', os.environ[CROS_BOARD_ENV]])
70 cmd.extend(['--cros_remote_ip', os.environ[CROS_IP_ENV]])
71 else:
72 print ('Error: Cros build selected, but BISECT_CROS_IP or'
73 'BISECT_CROS_BOARD undefined.\n')
74 return 1
75 elif 'android-chrome' == options.browser_type:
76 if not options.extra_src:
77 print 'Error: Missing --extra_src to run bisect for android-chrome.'
78 sys.exit(-1)
79 cmd.extend(['--target_platform', 'android-chrome'])
80 elif 'android' in options.browser_type:
81 cmd.extend(['--target_platform', 'android'])
82 elif not options.target_build_type:
83 cmd.extend(['--target_build_type', options.browser_type.title()])
85 if options.target_build_type:
86 cmd.extend(['--target_build_type', options.target_build_type])
88 if options.goma_threads:
89 cmd.extend(['--use_goma', '--goma_threads', options.goma_threads])
91 cmd = [str(c) for c in cmd]
93 return_code = subprocess.call(cmd)
95 if return_code:
96 print 'Error: bisect_perf_regression.py had exit code %d.' % return_code
97 print
99 return return_code
102 def main():
103 """Does a bisect based on the command-line arguments passed in.
105 The user will be prompted to classify each revision as good or bad.
107 usage = ('%prog [options]\n'
108 'Used to run the bisection script with a manual test.')
110 options = browser_options.BrowserFinderOptions('release')
111 parser = options.CreateParser(usage)
113 parser.add_option('-b', '--bad_revision',
114 type='str',
115 help='A bad revision to start bisection. ' +
116 'Must be later than good revision. May be either a git' +
117 ' or svn revision.')
118 parser.add_option('-g', '--good_revision',
119 type='str',
120 help='A revision to start bisection where performance' +
121 ' test is known to pass. Must be earlier than the ' +
122 'bad revision. May be either a git or svn revision.')
123 parser.add_option('-w', '--working_directory',
124 type='str',
125 default='..',
126 help='A working directory to supply to the bisection '
127 'script, which will use it as the location to checkout '
128 'a copy of the chromium depot.')
129 parser.add_option('--extra_src',
130 type='str',
131 help='Path to extra source file. If this is supplied, '
132 'bisect script will use this to override default behavior.')
133 parser.add_option('--target_build_type',
134 type='choice',
135 choices=['Release', 'Debug'],
136 help='The target build type. Choices are "Release" '
137 'or "Debug".')
138 parser.add_option('--goma_threads', default=64,
139 type='int',
140 help='Number of goma threads to use. 0 will disable goma.')
141 parser.add_option('--builder_type', default='',
142 choices=['perf',
143 'full',
144 'android-chrome-perf', ''],
145 help='Type of builder to get build from. This allows '
146 'script to use cached builds. By default (empty), binaries '
147 'are built locally.')
148 options, _ = parser.parse_args()
149 error_msg = ''
150 if not options.good_revision:
151 error_msg += 'Error: missing required parameter: --good_revision\n'
152 if not options.bad_revision:
153 error_msg += 'Error: missing required parameter: --bad_revision\n'
155 if error_msg:
156 print error_msg
157 parser.print_help()
158 return 1
160 if 'android' not in options.browser_type and sys.platform.startswith('linux'):
161 if not os.environ.get('CHROME_DEVEL_SANDBOX'):
162 print 'SUID sandbox has not been setup.'\
163 ' See https://code.google.com/p/chromium/wiki/'\
164 'LinuxSUIDSandboxDevelopment for more information.'
165 return 1
167 return _RunBisectionScript(options)
170 if __name__ == '__main__':
171 sys.exit(main())