| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Runs all types of tests from one unified interface. | 7 """Runs all types of tests from one unified interface. |
| 8 | 8 |
| 9 TODO(gkanwar): | 9 TODO(gkanwar): |
| 10 * Add options to run Monkey tests. | 10 * Add options to run Monkey tests. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 from pylib.gtest import gtest_config | 23 from pylib.gtest import gtest_config |
| 24 from pylib.gtest import setup as gtest_setup | 24 from pylib.gtest import setup as gtest_setup |
| 25 from pylib.gtest import test_options as gtest_test_options | 25 from pylib.gtest import test_options as gtest_test_options |
| 26 from pylib.host_driven import setup as host_driven_setup | 26 from pylib.host_driven import setup as host_driven_setup |
| 27 from pylib.instrumentation import setup as instrumentation_setup | 27 from pylib.instrumentation import setup as instrumentation_setup |
| 28 from pylib.instrumentation import test_options as instrumentation_test_options | 28 from pylib.instrumentation import test_options as instrumentation_test_options |
| 29 from pylib.monkey import setup as monkey_setup | 29 from pylib.monkey import setup as monkey_setup |
| 30 from pylib.monkey import test_options as monkey_test_options | 30 from pylib.monkey import test_options as monkey_test_options |
| 31 from pylib.uiautomator import setup as uiautomator_setup | 31 from pylib.uiautomator import setup as uiautomator_setup |
| 32 from pylib.uiautomator import test_options as uiautomator_test_options | 32 from pylib.uiautomator import test_options as uiautomator_test_options |
| 33 from pylib.utils import command_option_parser |
| 33 from pylib.utils import report_results | 34 from pylib.utils import report_results |
| 34 from pylib.utils import run_tests_helper | 35 from pylib.utils import run_tests_helper |
| 35 | 36 |
| 36 | 37 |
| 37 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') | 38 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
| 38 | 39 |
| 39 | 40 |
| 40 def AddBuildTypeOption(option_parser): | 41 def AddBuildTypeOption(option_parser): |
| 41 """Adds the build type option to |option_parser|.""" | 42 """Adds the build type option to |option_parser|.""" |
| 42 default_build_type = 'Debug' | 43 default_build_type = 'Debug' |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 option_parser.add_option('--python_test_root', | 218 option_parser.add_option('--python_test_root', |
| 218 help='Root of the host-driven tests.') | 219 help='Root of the host-driven tests.') |
| 219 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', | 220 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', |
| 220 action='store_true', | 221 action='store_true', |
| 221 help='Wait for debugger.') | 222 help='Wait for debugger.') |
| 222 option_parser.add_option( | 223 option_parser.add_option( |
| 223 '--test-apk', dest='test_apk', | 224 '--test-apk', dest='test_apk', |
| 224 help=('The name of the apk containing the tests ' | 225 help=('The name of the apk containing the tests ' |
| 225 '(without the .apk extension; e.g. "ContentShellTest"). ' | 226 '(without the .apk extension; e.g. "ContentShellTest"). ' |
| 226 'Alternatively, this can be a full path to the apk.')) | 227 'Alternatively, this can be a full path to the apk.')) |
| 228 option_parser.add_option('--coverage-dir', |
| 229 help=('Directory in which to place all generated ' |
| 230 'EMMA coverage files.')) |
| 227 | 231 |
| 228 | 232 |
| 229 def ProcessInstrumentationOptions(options, error_func): | 233 def ProcessInstrumentationOptions(options, error_func): |
| 230 """Processes options/arguments and populate |options| with defaults. | 234 """Processes options/arguments and populate |options| with defaults. |
| 231 | 235 |
| 232 Args: | 236 Args: |
| 233 options: optparse.Options object. | 237 options: optparse.Options object. |
| 234 error_func: Function to call with the error message in case of an error. | 238 error_func: Function to call with the error message in case of an error. |
| 235 | 239 |
| 236 Returns: | 240 Returns: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 options.tool, | 279 options.tool, |
| 276 options.cleanup_test_files, | 280 options.cleanup_test_files, |
| 277 options.push_deps, | 281 options.push_deps, |
| 278 options.annotations, | 282 options.annotations, |
| 279 options.exclude_annotations, | 283 options.exclude_annotations, |
| 280 options.test_filter, | 284 options.test_filter, |
| 281 options.test_data, | 285 options.test_data, |
| 282 options.save_perf_json, | 286 options.save_perf_json, |
| 283 options.screenshot_failures, | 287 options.screenshot_failures, |
| 284 options.wait_for_debugger, | 288 options.wait_for_debugger, |
| 289 options.coverage_dir, |
| 285 options.test_apk, | 290 options.test_apk, |
| 286 options.test_apk_path, | 291 options.test_apk_path, |
| 287 options.test_apk_jar_path) | 292 options.test_apk_jar_path) |
| 288 | 293 |
| 289 | 294 |
| 290 def AddUIAutomatorTestOptions(option_parser): | 295 def AddUIAutomatorTestOptions(option_parser): |
| 291 """Adds UI Automator test options to |option_parser|.""" | 296 """Adds UI Automator test options to |option_parser|.""" |
| 292 | 297 |
| 293 option_parser.usage = '%prog uiautomator [options]' | 298 option_parser.usage = '%prog uiautomator [options]' |
| 294 option_parser.command_list = [] | 299 option_parser.command_list = [] |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 'instrumentation': CommandFunctionTuple( | 641 'instrumentation': CommandFunctionTuple( |
| 637 AddInstrumentationTestOptions, RunTestsCommand), | 642 AddInstrumentationTestOptions, RunTestsCommand), |
| 638 'uiautomator': CommandFunctionTuple( | 643 'uiautomator': CommandFunctionTuple( |
| 639 AddUIAutomatorTestOptions, RunTestsCommand), | 644 AddUIAutomatorTestOptions, RunTestsCommand), |
| 640 'monkey': CommandFunctionTuple( | 645 'monkey': CommandFunctionTuple( |
| 641 AddMonkeyTestOptions, RunTestsCommand), | 646 AddMonkeyTestOptions, RunTestsCommand), |
| 642 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 647 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
| 643 } | 648 } |
| 644 | 649 |
| 645 | 650 |
| 646 class CommandOptionParser(optparse.OptionParser): | |
| 647 """Wrapper class for OptionParser to help with listing commands.""" | |
| 648 | |
| 649 def __init__(self, *args, **kwargs): | |
| 650 self.command_list = kwargs.pop('command_list', []) | |
| 651 self.example = kwargs.pop('example', '') | |
| 652 optparse.OptionParser.__init__(self, *args, **kwargs) | |
| 653 | |
| 654 #override | |
| 655 def get_usage(self): | |
| 656 normal_usage = optparse.OptionParser.get_usage(self) | |
| 657 command_list = self.get_command_list() | |
| 658 example = self.get_example() | |
| 659 return self.expand_prog_name(normal_usage + example + command_list) | |
| 660 | |
| 661 #override | |
| 662 def get_command_list(self): | |
| 663 if self.command_list: | |
| 664 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list)) | |
| 665 return '' | |
| 666 | |
| 667 def get_example(self): | |
| 668 if self.example: | |
| 669 return '\nExample:\n %s\n' % self.example | |
| 670 return '' | |
| 671 | |
| 672 | |
| 673 def main(argv): | 651 def main(argv): |
| 674 option_parser = CommandOptionParser( | 652 option_parser = command_option_parser.CommandOptionParser( |
| 675 usage='Usage: %prog <command> [options]', | 653 commands_dict=VALID_COMMANDS) |
| 676 command_list=VALID_COMMANDS.keys()) | 654 return command_option_parser.ParseAndExecute(option_parser) |
| 677 | |
| 678 if len(argv) < 2 or argv[1] not in VALID_COMMANDS: | |
| 679 option_parser.print_help() | |
| 680 return 0 | |
| 681 command = argv[1] | |
| 682 VALID_COMMANDS[command].add_options_func(option_parser) | |
| 683 options, args = option_parser.parse_args(argv) | |
| 684 return VALID_COMMANDS[command].run_command_func( | |
| 685 command, options, args, option_parser) | |
| 686 | 655 |
| 687 | 656 |
| 688 if __name__ == '__main__': | 657 if __name__ == '__main__': |
| 689 sys.exit(main(sys.argv)) | 658 sys.exit(main(sys.argv)) |
| OLD | NEW |