| 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 15 matching lines...) Expand all Loading... |
| 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.perf import setup as perf_setup | 31 from pylib.perf import setup as perf_setup |
| 32 from pylib.perf import test_options as perf_test_options | 32 from pylib.perf import test_options as perf_test_options |
| 33 from pylib.perf import test_runner as perf_test_runner | 33 from pylib.perf import test_runner as perf_test_runner |
| 34 from pylib.uiautomator import setup as uiautomator_setup | 34 from pylib.uiautomator import setup as uiautomator_setup |
| 35 from pylib.uiautomator import test_options as uiautomator_test_options | 35 from pylib.uiautomator import test_options as uiautomator_test_options |
| 36 from pylib.utils import command_option_parser |
| 36 from pylib.utils import report_results | 37 from pylib.utils import report_results |
| 37 from pylib.utils import run_tests_helper | 38 from pylib.utils import run_tests_helper |
| 38 | 39 |
| 39 | 40 |
| 40 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') | 41 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
| 41 | 42 |
| 42 | 43 |
| 43 def AddBuildTypeOption(option_parser): | 44 def AddBuildTypeOption(option_parser): |
| 44 """Adds the build type option to |option_parser|.""" | 45 """Adds the build type option to |option_parser|.""" |
| 45 default_build_type = 'Debug' | 46 default_build_type = 'Debug' |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 option_parser.add_option('--host-driven-root', | 222 option_parser.add_option('--host-driven-root', |
| 222 help='Root of the host-driven tests.') | 223 help='Root of the host-driven tests.') |
| 223 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', | 224 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', |
| 224 action='store_true', | 225 action='store_true', |
| 225 help='Wait for debugger.') | 226 help='Wait for debugger.') |
| 226 option_parser.add_option( | 227 option_parser.add_option( |
| 227 '--test-apk', dest='test_apk', | 228 '--test-apk', dest='test_apk', |
| 228 help=('The name of the apk containing the tests ' | 229 help=('The name of the apk containing the tests ' |
| 229 '(without the .apk extension; e.g. "ContentShellTest"). ' | 230 '(without the .apk extension; e.g. "ContentShellTest"). ' |
| 230 'Alternatively, this can be a full path to the apk.')) | 231 'Alternatively, this can be a full path to the apk.')) |
| 232 option_parser.add_option('--coverage-dir', |
| 233 help=('Directory in which to place all generated ' |
| 234 'EMMA coverage files.')) |
| 231 | 235 |
| 232 | 236 |
| 233 def ProcessInstrumentationOptions(options, error_func): | 237 def ProcessInstrumentationOptions(options, error_func): |
| 234 """Processes options/arguments and populate |options| with defaults. | 238 """Processes options/arguments and populate |options| with defaults. |
| 235 | 239 |
| 236 Args: | 240 Args: |
| 237 options: optparse.Options object. | 241 options: optparse.Options object. |
| 238 error_func: Function to call with the error message in case of an error. | 242 error_func: Function to call with the error message in case of an error. |
| 239 | 243 |
| 240 Returns: | 244 Returns: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 options.tool, | 282 options.tool, |
| 279 options.cleanup_test_files, | 283 options.cleanup_test_files, |
| 280 options.push_deps, | 284 options.push_deps, |
| 281 options.annotations, | 285 options.annotations, |
| 282 options.exclude_annotations, | 286 options.exclude_annotations, |
| 283 options.test_filter, | 287 options.test_filter, |
| 284 options.test_data, | 288 options.test_data, |
| 285 options.save_perf_json, | 289 options.save_perf_json, |
| 286 options.screenshot_failures, | 290 options.screenshot_failures, |
| 287 options.wait_for_debugger, | 291 options.wait_for_debugger, |
| 292 options.coverage_dir, |
| 288 options.test_apk, | 293 options.test_apk, |
| 289 options.test_apk_path, | 294 options.test_apk_path, |
| 290 options.test_apk_jar_path) | 295 options.test_apk_jar_path) |
| 291 | 296 |
| 292 | 297 |
| 293 def AddUIAutomatorTestOptions(option_parser): | 298 def AddUIAutomatorTestOptions(option_parser): |
| 294 """Adds UI Automator test options to |option_parser|.""" | 299 """Adds UI Automator test options to |option_parser|.""" |
| 295 | 300 |
| 296 option_parser.usage = '%prog uiautomator [options]' | 301 option_parser.usage = '%prog uiautomator [options]' |
| 297 option_parser.command_list = [] | 302 option_parser.command_list = [] |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 'uiautomator': CommandFunctionTuple( | 699 'uiautomator': CommandFunctionTuple( |
| 695 AddUIAutomatorTestOptions, RunTestsCommand), | 700 AddUIAutomatorTestOptions, RunTestsCommand), |
| 696 'monkey': CommandFunctionTuple( | 701 'monkey': CommandFunctionTuple( |
| 697 AddMonkeyTestOptions, RunTestsCommand), | 702 AddMonkeyTestOptions, RunTestsCommand), |
| 698 'perf': CommandFunctionTuple( | 703 'perf': CommandFunctionTuple( |
| 699 AddPerfTestOptions, RunTestsCommand), | 704 AddPerfTestOptions, RunTestsCommand), |
| 700 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 705 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
| 701 } | 706 } |
| 702 | 707 |
| 703 | 708 |
| 704 class CommandOptionParser(optparse.OptionParser): | |
| 705 """Wrapper class for OptionParser to help with listing commands.""" | |
| 706 | |
| 707 def __init__(self, *args, **kwargs): | |
| 708 self.command_list = kwargs.pop('command_list', []) | |
| 709 self.example = kwargs.pop('example', '') | |
| 710 optparse.OptionParser.__init__(self, *args, **kwargs) | |
| 711 | |
| 712 #override | |
| 713 def get_usage(self): | |
| 714 normal_usage = optparse.OptionParser.get_usage(self) | |
| 715 command_list = self.get_command_list() | |
| 716 example = self.get_example() | |
| 717 return self.expand_prog_name(normal_usage + example + command_list) | |
| 718 | |
| 719 #override | |
| 720 def get_command_list(self): | |
| 721 if self.command_list: | |
| 722 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list)) | |
| 723 return '' | |
| 724 | |
| 725 def get_example(self): | |
| 726 if self.example: | |
| 727 return '\nExample:\n %s\n' % self.example | |
| 728 return '' | |
| 729 | |
| 730 | |
| 731 def main(argv): | 709 def main(argv): |
| 732 option_parser = CommandOptionParser( | 710 option_parser = command_option_parser.CommandOptionParser( |
| 733 usage='Usage: %prog <command> [options]', | 711 commands_dict=VALID_COMMANDS) |
| 734 command_list=VALID_COMMANDS.keys()) | 712 return command_option_parser.ParseAndExecute(option_parser) |
| 735 | |
| 736 if len(argv) < 2 or argv[1] not in VALID_COMMANDS: | |
| 737 # Parse args first, if this is '--help', optparse will display help and exit | |
| 738 option_parser.parse_args(argv) | |
| 739 option_parser.error('Invalid command.') | |
| 740 command = argv[1] | |
| 741 VALID_COMMANDS[command].add_options_func(option_parser) | |
| 742 options, args = option_parser.parse_args(argv) | |
| 743 return VALID_COMMANDS[command].run_command_func( | |
| 744 command, options, args, option_parser) | |
| 745 | 713 |
| 746 | 714 |
| 747 if __name__ == '__main__': | 715 if __name__ == '__main__': |
| 748 sys.exit(main(sys.argv)) | 716 sys.exit(main(sys.argv)) |
| OLD | NEW |