- add sources.
[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 """
17
18 import os
19 import subprocess
20 import sys
21
22 CROS_BOARD_ENV = 'BISECT_CROS_BOARD'
23 CROS_IP_ENV = 'BISECT_CROS_IP'
24 _DIR_TOOLS_ROOT = os.path.abspath(os.path.dirname(__file__))
25
26 sys.path.append(os.path.join(_DIR_TOOLS_ROOT, 'telemetry'))
27 from telemetry.core import browser_options
28
29
30 def _RunBisectionScript(options):
31   """Attempts to execute src/tools/bisect-perf-regression.py with the parameters
32   passed in.
33
34   Args:
35     options: The configuration options to pass to the bisect script.
36
37   Returns:
38     0 on success, otherwise 1.
39   """
40   test_command = 'python %s --browser=%s --chrome-root=.' %\
41       (os.path.join(_DIR_TOOLS_ROOT, 'bisect-manual-test.py'),
42        options.browser_type)
43
44   cmd = ['python', os.path.join(_DIR_TOOLS_ROOT, 'bisect-perf-regression.py'),
45          '-c', test_command,
46          '-g', options.good_revision,
47          '-b', options.bad_revision,
48          '-m', 'manual_test/manual_test',
49          '-r', '1',
50          '--working_directory', options.working_directory,
51          '--build_preference', 'ninja',
52          '--use_goma',
53          '--no_custom_deps']
54
55   if 'cros' in options.browser_type:
56     cmd.extend(['--target_platform', 'cros'])
57
58     if os.environ[CROS_BOARD_ENV] and os.environ[CROS_IP_ENV]:
59       cmd.extend(['--cros_board', os.environ[CROS_BOARD_ENV]])
60       cmd.extend(['--cros_remote_ip', os.environ[CROS_IP_ENV]])
61     else:
62       print 'Error: Cros build selected, but BISECT_CROS_IP or'\
63             'BISECT_CROS_BOARD undefined.'
64       print
65       return 1
66   elif 'android' in options.browser_type:
67     cmd.extend(['--target_platform', 'android'])
68
69   cmd = [str(c) for c in cmd]
70
71   return_code = subprocess.call(cmd)
72
73   if return_code:
74     print 'Error: bisect-perf-regression.py returned with error %d' %\
75         return_code
76     print
77
78   return return_code
79
80
81 def main():
82   usage = ('%prog [options]\n'
83            'Used to run the bisection script with a manual test.')
84
85   options = browser_options.BrowserFinderOptions('release')
86   parser = options.CreateParser(usage)
87
88   parser.add_option('-b', '--bad_revision',
89                     type='str',
90                     help='A bad revision to start bisection. ' +
91                     'Must be later than good revision. May be either a git' +
92                     ' or svn revision.')
93   parser.add_option('-g', '--good_revision',
94                     type='str',
95                     help='A revision to start bisection where performance' +
96                     ' test is known to pass. Must be earlier than the ' +
97                     'bad revision. May be either a git or svn revision.')
98   parser.add_option('-w', '--working_directory',
99                     type='str',
100                     default='..',
101                     help='A working directory to supply to the bisection '
102                     'script, which will use it as the location to checkout '
103                     'a copy of the chromium depot.')
104
105   options, args = parser.parse_args()
106   error_msg = ''
107   if not options.good_revision:
108     error_msg += 'Error: missing required parameter: --good_revision\n'
109   if not options.bad_revision:
110     error_msg += 'Error: missing required parameter: --bad_revision\n'
111
112   if error_msg:
113     print error_msg
114     parser.print_help()
115     return 1
116
117   if sys.platform.startswith('linux'):
118     if not os.environ.get('CHROME_DEVEL_SANDBOX'):
119       print 'SUID sandbox has not been setup.'\
120             ' See https://code.google.com/p/chromium/wiki/'\
121             'LinuxSUIDSandboxDevelopment for more information.'
122       return 1
123
124   return _RunBisectionScript(options)
125
126
127 if __name__ == '__main__':
128   sys.exit(main())