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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', | 274 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger', |
275 action='store_true', | 275 action='store_true', |
276 help='Wait for debugger.') | 276 help='Wait for debugger.') |
277 option_parser.add_option('-I', dest='install_apk', action='store_true', | 277 option_parser.add_option('-I', dest='install_apk', action='store_true', |
278 help='Install test APK.') | 278 help='Install test APK.') |
279 option_parser.add_option( | 279 option_parser.add_option( |
280 '--test-apk', dest='test_apk', | 280 '--test-apk', dest='test_apk', |
281 help=('The name of the apk containing the tests ' | 281 help=('The name of the apk containing the tests ' |
282 '(without the .apk extension; e.g. "ContentShellTest"). ' | 282 '(without the .apk extension; e.g. "ContentShellTest"). ' |
283 'Alternatively, this can be a full path to the apk.')) | 283 'Alternatively, this can be a full path to the apk.')) |
284 option_parser.add_option('--coverage', action='store_true', default=False, | |
285 help=('Run instrumentation tests with the EMMA ' | |
286 'coverage tool.')) | |
287 option_parser.add_option('--coverage_dir', default=None, | |
288 help=('Directory in which to place all generated ' | |
289 'EMMA coverage files.')) | |
frankf
2013/07/25 18:53:44
Just use coverage_dir to enable coverage
gkanwar1
2013/07/25 19:06:38
Good point. Updated.
| |
284 | 290 |
285 | 291 |
286 def ProcessInstrumentationOptions(options, error_func): | 292 def ProcessInstrumentationOptions(options, error_func): |
287 """Processes options/arguments and populate |options| with defaults.""" | 293 """Processes options/arguments and populate |options| with defaults.""" |
288 | 294 |
289 ProcessJavaTestOptions(options, error_func) | 295 ProcessJavaTestOptions(options, error_func) |
290 | 296 |
291 if not options.test_apk: | 297 if not options.test_apk: |
292 error_func('--test-apk must be specified.') | 298 error_func('--test-apk must be specified.') |
293 | 299 |
294 if os.path.exists(options.test_apk): | 300 if os.path.exists(options.test_apk): |
295 # The APK is fully qualified, assume the JAR lives along side. | 301 # The APK is fully qualified, assume the JAR lives along side. |
296 options.test_apk_path = options.test_apk | 302 options.test_apk_path = options.test_apk |
297 options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] + | 303 options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] + |
298 '.jar') | 304 '.jar') |
299 else: | 305 else: |
300 options.test_apk_path = os.path.join(_SDK_OUT_DIR, | 306 options.test_apk_path = os.path.join(_SDK_OUT_DIR, |
301 options.build_type, | 307 options.build_type, |
302 constants.SDK_BUILD_APKS_DIR, | 308 constants.SDK_BUILD_APKS_DIR, |
303 '%s.apk' % options.test_apk) | 309 '%s.apk' % options.test_apk) |
304 options.test_apk_jar_path = os.path.join( | 310 options.test_apk_jar_path = os.path.join( |
305 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR, | 311 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR, |
306 '%s.jar' % options.test_apk) | 312 '%s.jar' % options.test_apk) |
307 | 313 |
314 if options.coverage and not options.coverage_dir: | |
315 error_func('--coverage_dir must be specified if running with coverage.') | |
316 | |
308 | 317 |
309 def AddUIAutomatorTestOptions(option_parser): | 318 def AddUIAutomatorTestOptions(option_parser): |
310 """Adds UI Automator test options to |option_parser|.""" | 319 """Adds UI Automator test options to |option_parser|.""" |
311 | 320 |
312 option_parser.usage = '%prog uiautomator [options]' | 321 option_parser.usage = '%prog uiautomator [options]' |
313 option_parser.command_list = [] | 322 option_parser.command_list = [] |
314 option_parser.example = ( | 323 option_parser.example = ( |
315 '%prog uiautomator --test-jar=chromium_testshell_uiautomator_tests' | 324 '%prog uiautomator --test-jar=chromium_testshell_uiautomator_tests' |
316 ' --package-name=org.chromium.chrome.testshell') | 325 ' --package-name=org.chromium.chrome.testshell') |
317 option_parser.add_option( | 326 option_parser.add_option( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 results = base_test_result.TestRunResults() | 433 results = base_test_result.TestRunResults() |
425 exit_code = 0 | 434 exit_code = 0 |
426 | 435 |
427 if options.run_java_tests: | 436 if options.run_java_tests: |
428 runner_factory, tests = instrumentation_setup.Setup( | 437 runner_factory, tests = instrumentation_setup.Setup( |
429 options.test_apk_path, options.test_apk_jar_path, options.annotations, | 438 options.test_apk_path, options.test_apk_jar_path, options.annotations, |
430 options.exclude_annotations, options.test_filter, options.build_type, | 439 options.exclude_annotations, options.test_filter, options.build_type, |
431 options.test_data, options.install_apk, options.save_perf_json, | 440 options.test_data, options.install_apk, options.save_perf_json, |
432 options.screenshot_failures, options.tool, options.wait_for_debugger, | 441 options.screenshot_failures, options.tool, options.wait_for_debugger, |
433 options.disable_assertions, options.push_deps, | 442 options.disable_assertions, options.push_deps, |
434 options.cleanup_test_files) | 443 options.cleanup_test_files, options.coverage, options.coverage_dir) |
435 | 444 |
436 test_results, exit_code = test_dispatcher.RunTests( | 445 test_results, exit_code = test_dispatcher.RunTests( |
437 tests, runner_factory, options.wait_for_debugger, | 446 tests, runner_factory, options.wait_for_debugger, |
438 options.test_device, | 447 options.test_device, |
439 shard=True, | 448 shard=True, |
440 build_type=options.build_type, | 449 build_type=options.build_type, |
441 test_timeout=None, | 450 test_timeout=None, |
442 num_retries=options.num_retries) | 451 num_retries=options.num_retries) |
443 | 452 |
444 results.AddTestRunResults(test_results) | 453 results.AddTestRunResults(test_results) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 return 0 | 653 return 0 |
645 command = argv[1] | 654 command = argv[1] |
646 VALID_COMMANDS[command].add_options_func(option_parser) | 655 VALID_COMMANDS[command].add_options_func(option_parser) |
647 options, args = option_parser.parse_args(argv) | 656 options, args = option_parser.parse_args(argv) |
648 return VALID_COMMANDS[command].run_command_func( | 657 return VALID_COMMANDS[command].run_command_func( |
649 command, options, args, option_parser) | 658 command, options, args, option_parser) |
650 | 659 |
651 | 660 |
652 if __name__ == '__main__': | 661 if __name__ == '__main__': |
653 sys.exit(main(sys.argv)) | 662 sys.exit(main(sys.argv)) |
OLD | NEW |