[Sync] Fix invalidations on Android.
[chromium-blink-merge.git] / tools / run-bisect-manual-test.py
blob96a7b0d919cd8dd55e7bc7fd11fccc9c1ccb284f
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 test_command = ('python %s --browser=%s --chrome-root=.' %
45 (os.path.join(_TOOLS_DIR, 'bisect-manual-test.py'),
46 options.browser_type))
48 cmd = ['python', _BISECT_SCRIPT_PATH,
49 '-c', test_command,
50 '-g', options.good_revision,
51 '-b', options.bad_revision,
52 '-m', 'manual_test/manual_test',
53 '-r', '1',
54 '--working_directory', options.working_directory,
55 '--build_preference', 'ninja',
56 '--use_goma',
57 '--no_custom_deps']
59 if options.extra_src:
60 cmd.extend(['--extra_src', options.extra_src])
62 if 'cros' in options.browser_type:
63 cmd.extend(['--target_platform', 'cros'])
65 if os.environ[CROS_BOARD_ENV] and os.environ[CROS_IP_ENV]:
66 cmd.extend(['--cros_board', os.environ[CROS_BOARD_ENV]])
67 cmd.extend(['--cros_remote_ip', os.environ[CROS_IP_ENV]])
68 else:
69 print ('Error: Cros build selected, but BISECT_CROS_IP or'
70 'BISECT_CROS_BOARD undefined.\n')
71 return 1
72 elif 'android-chrome' in options.browser_type:
73 cmd.extend(['--target_platform', 'android-chrome'])
74 elif 'android' in options.browser_type:
75 cmd.extend(['--target_platform', 'android'])
76 elif not options.target_build_type:
77 cmd.extend(['--target_build_type', options.browser_type.title()])
79 if options.target_build_type:
80 cmd.extend(['--target_build_type', options.target_build_type])
82 if options.goma_threads:
83 cmd.extend(['--goma_threads', options.goma_threads])
85 cmd = [str(c) for c in cmd]
87 return_code = subprocess.call(cmd)
89 if return_code:
90 print 'Error: bisect_perf_regression.py had exit code %d.' % return_code
91 print
93 return return_code
96 def main():
97 """Does a bisect based on the command-line arguments passed in.
99 The user will be prompted to classify each revision as good or bad.
101 usage = ('%prog [options]\n'
102 'Used to run the bisection script with a manual test.')
104 options = browser_options.BrowserFinderOptions('release')
105 parser = options.CreateParser(usage)
107 parser.add_option('-b', '--bad_revision',
108 type='str',
109 help='A bad revision to start bisection. ' +
110 'Must be later than good revision. May be either a git' +
111 ' or svn revision.')
112 parser.add_option('-g', '--good_revision',
113 type='str',
114 help='A revision to start bisection where performance' +
115 ' test is known to pass. Must be earlier than the ' +
116 'bad revision. May be either a git or svn revision.')
117 parser.add_option('-w', '--working_directory',
118 type='str',
119 default='..',
120 help='A working directory to supply to the bisection '
121 'script, which will use it as the location to checkout '
122 'a copy of the chromium depot.')
123 parser.add_option('--extra_src',
124 type='str',
125 help='Path to extra source file. If this is supplied, '
126 'bisect script will use this to override default behavior.')
127 parser.add_option('--target_build_type',
128 type='choice',
129 choices=['Release', 'Debug'],
130 help='The target build type. Choices are "Release" '
131 'or "Debug".')
132 parser.add_option('--goma_threads',
133 type='int',
134 help='Number of goma threads to use.')
135 options, _ = parser.parse_args()
136 error_msg = ''
137 if not options.good_revision:
138 error_msg += 'Error: missing required parameter: --good_revision\n'
139 if not options.bad_revision:
140 error_msg += 'Error: missing required parameter: --bad_revision\n'
142 if error_msg:
143 print error_msg
144 parser.print_help()
145 return 1
147 if 'android' not in options.browser_type and sys.platform.startswith('linux'):
148 if not os.environ.get('CHROME_DEVEL_SANDBOX'):
149 print 'SUID sandbox has not been setup.'\
150 ' See https://code.google.com/p/chromium/wiki/'\
151 'LinuxSUIDSandboxDevelopment for more information.'
152 return 1
154 return _RunBisectionScript(options)
157 if __name__ == '__main__':
158 sys.exit(main())