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