Home | History | Annotate | Download | only in sharding_supervisor
      1 #!/usr/bin/env python
      2 # Copyright (c) 2012 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 """Defer to run_test_cases.py."""
      7 
      8 import os
      9 import optparse
     10 import sys
     11 
     12 ROOT_DIR = os.path.dirname(
     13     os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
     14 
     15 
     16 def pop_known_arguments(args):
     17   """Extracts known arguments from the args if present."""
     18   rest = []
     19   run_test_cases_extra_args = []
     20   for arg in args:
     21     if arg.startswith(('--gtest_filter=', '--gtest_output=')):
     22       run_test_cases_extra_args.append(arg)
     23     elif arg == '--run-manual':
     24       run_test_cases_extra_args.append(arg)
     25     elif arg == '--gtest_print_time':
     26       # Ignore.
     27       pass
     28     elif 'interactive_ui_tests' in arg:
     29       # Run this test in a single thread. It is useful to run it under
     30       # run_test_cases so automatic flaky test workaround is still used.
     31       run_test_cases_extra_args.append('-j1')
     32       rest.append(arg)
     33     elif 'browser_tests' in arg:
     34       # Test cases in this executable fire up *a lot* of child processes,
     35       # causing huge memory bottleneck. So use less than N-cpus jobs.
     36       run_test_cases_extra_args.append('--use-less-jobs')
     37       rest.append(arg)
     38     else:
     39       rest.append(arg)
     40   return run_test_cases_extra_args, rest
     41 
     42 
     43 def main():
     44   parser = optparse.OptionParser()
     45 
     46   group = optparse.OptionGroup(
     47       parser, 'Compability flag with the old sharding_supervisor')
     48   group.add_option(
     49       '--no-color', action='store_true', help='Ignored')
     50   group.add_option(
     51       '--retry-failed', action='store_true', help='Ignored')
     52   group.add_option(
     53       '-t', '--timeout', type='int', help='Kept as --timeout')
     54   group.add_option(
     55       '--total-slaves', type='int', default=1, help='Converted to --index')
     56   group.add_option(
     57       '--slave-index', type='int', default=0, help='Converted to --shards')
     58   parser.add_option_group(group)
     59 
     60   parser.disable_interspersed_args()
     61   options, args = parser.parse_args()
     62 
     63   swarm_client_dir = os.path.join(
     64       ROOT_DIR, 'tools', 'swarm_client', 'googletest')
     65   sys.path.insert(0, swarm_client_dir)
     66 
     67   cmd = [
     68     '--shards', str(options.total_slaves),
     69     '--index', str(options.slave_index),
     70     '--no-dump',
     71     '--no-cr',
     72   ]
     73   if options.timeout is not None:
     74     cmd.extend(['--timeout', str(options.timeout)])
     75 
     76   run_test_cases_extra_args, rest = pop_known_arguments(args)
     77 
     78   import run_test_cases  # pylint: disable=F0401
     79 
     80   return run_test_cases.main(cmd + run_test_cases_extra_args + ['--'] + rest)
     81 
     82 
     83 if __name__ == '__main__':
     84   sys.exit(main())
     85