Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: build/android/test_runner.py

Issue 20210002: [Android] Sets up a coverage system for java using EMMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Break apart native and java coverage flags for gyp Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 'instrumentation': CommandFunctionTuple( 647 'instrumentation': CommandFunctionTuple(
643 AddInstrumentationTestOptions, RunTestsCommand), 648 AddInstrumentationTestOptions, RunTestsCommand),
644 'uiautomator': CommandFunctionTuple( 649 'uiautomator': CommandFunctionTuple(
645 AddUIAutomatorTestOptions, RunTestsCommand), 650 AddUIAutomatorTestOptions, RunTestsCommand),
646 'monkey': CommandFunctionTuple( 651 'monkey': CommandFunctionTuple(
647 AddMonkeyTestOptions, RunTestsCommand), 652 AddMonkeyTestOptions, RunTestsCommand),
648 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) 653 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand)
649 } 654 }
650 655
651 656
652 class CommandOptionParser(optparse.OptionParser):
653 """Wrapper class for OptionParser to help with listing commands."""
654
655 def __init__(self, *args, **kwargs):
656 self.command_list = kwargs.pop('command_list', [])
657 self.example = kwargs.pop('example', '')
658 optparse.OptionParser.__init__(self, *args, **kwargs)
659
660 #override
661 def get_usage(self):
662 normal_usage = optparse.OptionParser.get_usage(self)
663 command_list = self.get_command_list()
664 example = self.get_example()
665 return self.expand_prog_name(normal_usage + example + command_list)
666
667 #override
668 def get_command_list(self):
669 if self.command_list:
670 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list))
671 return ''
672
673 def get_example(self):
674 if self.example:
675 return '\nExample:\n %s\n' % self.example
676 return ''
677
678
679 def main(argv): 657 def main(argv):
680 option_parser = CommandOptionParser( 658 option_parser = command_option_parser.CommandOptionParser(
681 usage='Usage: %prog <command> [options]', 659 commands_dict=VALID_COMMANDS)
682 command_list=VALID_COMMANDS.keys()) 660 return command_option_parser.ParseAndExecute(option_parser)
683
684 if len(argv) < 2 or argv[1] not in VALID_COMMANDS:
685 option_parser.error('Invalid command.')
686 command = argv[1]
687 VALID_COMMANDS[command].add_options_func(option_parser)
688 options, args = option_parser.parse_args(argv)
689 return VALID_COMMANDS[command].run_command_func(
690 command, options, args, option_parser)
691 661
692 662
693 if __name__ == '__main__': 663 if __name__ == '__main__':
694 sys.exit(main(sys.argv)) 664 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698