Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / tools / run-bisect-manual-test.py
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.
5
6 """Run Manual Test Bisect Tool
7
8 An example usage:
9 tools/run-bisect-manual-test.py -g 201281 -b 201290
10
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.
15
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 actually check out
18 and build revisions of Chromium that are not available in cloud storage.
19 """
20
21 import os
22 import subprocess
23 import sys
24
25 CROS_BOARD_ENV = 'BISECT_CROS_BOARD'
26 CROS_IP_ENV = 'BISECT_CROS_IP'
27 _DIR_TOOLS_ROOT = os.path.abspath(os.path.dirname(__file__))
28
29 sys.path.append(os.path.join(_DIR_TOOLS_ROOT, 'telemetry'))
30 from telemetry.core import browser_options
31
32
33 def _RunBisectionScript(options):
34   """Attempts to execute src/tools/bisect-perf-regression.py.
35
36   Args:
37     options: The configuration options to pass to the bisect script.
38
39   Returns:
40     The exit code of bisect-perf-regression.py: 0 on success, otherwise 1.
41   """
42   test_command = ('python %s --browser=%s --chrome-root=.' %
43                   (os.path.join(_DIR_TOOLS_ROOT, 'bisect-manual-test.py'),
44                    options.browser_type))
45
46   cmd = ['python', os.path.join(_DIR_TOOLS_ROOT, 'bisect-perf-regression.py'),
47          '-c', test_command,
48          '-g', options.good_revision,
49          '-b', options.bad_revision,
50          '-m', 'manual_test/manual_test',
51          '-r', '1',
52          '--working_directory', options.working_directory,
53          '--build_preference', 'ninja',
54          '--use_goma',
55          '--no_custom_deps']
56
57   if options.extra_src:
58     cmd.extend(['--extra_src', options.extra_src])
59
60   if 'cros' in options.browser_type:
61     cmd.extend(['--target_platform', 'cros'])
62
63     if os.environ[CROS_BOARD_ENV] and os.environ[CROS_IP_ENV]:
64       cmd.extend(['--cros_board', os.environ[CROS_BOARD_ENV]])
65       cmd.extend(['--cros_remote_ip', os.environ[CROS_IP_ENV]])
66     else:
67       print ('Error: Cros build selected, but BISECT_CROS_IP or'
68              'BISECT_CROS_BOARD undefined.\n')
69       return 1
70   elif 'android-chrome' in options.browser_type:
71     cmd.extend(['--target_platform', 'android-chrome'])
72   elif 'android' in options.browser_type:
73     cmd.extend(['--target_platform', 'android'])
74   elif not options.target_build_type:
75     cmd.extend(['--target_build_type', options.browser_type.title()])
76
77   if options.target_build_type:
78     cmd.extend(['--target_build_type', options.target_build_type])
79
80   cmd = [str(c) for c in cmd]
81
82   return_code = subprocess.call(cmd)
83
84   if return_code:
85     print ('Error: bisect-perf-regression.py returned with error %d' %
86            return_code)
87     print
88
89   return return_code
90
91
92 def main():
93   """Does a bisect based on the command-line arguments passed in.
94
95   The user will be prompted to classify each revision as good or bad.
96   """
97   usage = ('%prog [options]\n'
98            'Used to run the bisection script with a manual test.')
99
100   options = browser_options.BrowserFinderOptions('release')
101   parser = options.CreateParser(usage)
102
103   parser.add_option('-b', '--bad_revision',
104                     type='str',
105                     help='A bad revision to start bisection. ' +
106                     'Must be later than good revision. May be either a git' +
107                     ' or svn revision.')
108   parser.add_option('-g', '--good_revision',
109                     type='str',
110                     help='A revision to start bisection where performance' +
111                     ' test is known to pass. Must be earlier than the ' +
112                     'bad revision. May be either a git or svn revision.')
113   parser.add_option('-w', '--working_directory',
114                     type='str',
115                     default='..',
116                     help='A working directory to supply to the bisection '
117                     'script, which will use it as the location to checkout '
118                     'a copy of the chromium depot.')
119   parser.add_option('--extra_src',
120                     type='str',
121                     help='Path to extra source file. If this is supplied, '
122                     'bisect script will use this to override default behavior.')
123   parser.add_option('--target_build_type',
124                      type='choice',
125                      choices=['Release', 'Debug'],
126                      help='The target build type. Choices are "Release" '
127                      'or "Debug".')
128   options, _ = parser.parse_args()
129   error_msg = ''
130   if not options.good_revision:
131     error_msg += 'Error: missing required parameter: --good_revision\n'
132   if not options.bad_revision:
133     error_msg += 'Error: missing required parameter: --bad_revision\n'
134
135   if error_msg:
136     print error_msg
137     parser.print_help()
138     return 1
139
140   if 'android' not in options.browser_type and sys.platform.startswith('linux'):
141     if not os.environ.get('CHROME_DEVEL_SANDBOX'):
142       print 'SUID sandbox has not been setup.'\
143             ' See https://code.google.com/p/chromium/wiki/'\
144             'LinuxSUIDSandboxDevelopment for more information.'
145       return 1
146
147   return _RunBisectionScript(options)
148
149
150 if __name__ == '__main__':
151   sys.exit(main())