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

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

Issue 22933005: [android] Make build_type a singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 'Use this at own risk for speeding up test ' 84 'Use this at own risk for speeding up test '
85 'execution on local machine.')) 85 'execution on local machine.'))
86 option_parser.add_option('-d', '--device', dest='test_device', 86 option_parser.add_option('-d', '--device', dest='test_device',
87 help=('Target device for the test suite ' 87 help=('Target device for the test suite '
88 'to run on.')) 88 'to run on.'))
89 89
90 90
91 def ProcessCommonOptions(options): 91 def ProcessCommonOptions(options):
92 """Processes and handles all common options.""" 92 """Processes and handles all common options."""
93 run_tests_helper.SetLogLevel(options.verbose_count) 93 run_tests_helper.SetLogLevel(options.verbose_count)
94 constants.SetBuildType(options.build_type)
94 95
95 96
96 def AddGTestOptions(option_parser): 97 def AddGTestOptions(option_parser):
97 """Adds gtest options to |option_parser|.""" 98 """Adds gtest options to |option_parser|."""
98 99
99 option_parser.usage = '%prog gtest [options]' 100 option_parser.usage = '%prog gtest [options]'
100 option_parser.command_list = [] 101 option_parser.command_list = []
101 option_parser.example = '%prog gtest -s base_unittests' 102 option_parser.example = '%prog gtest -s base_unittests'
102 103
103 # TODO(gkanwar): Make this option required 104 # TODO(gkanwar): Make this option required
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 else: 265 else:
265 options.test_apk_path = os.path.join(_SDK_OUT_DIR, 266 options.test_apk_path = os.path.join(_SDK_OUT_DIR,
266 options.build_type, 267 options.build_type,
267 constants.SDK_BUILD_APKS_DIR, 268 constants.SDK_BUILD_APKS_DIR,
268 '%s.apk' % options.test_apk) 269 '%s.apk' % options.test_apk)
269 options.test_apk_jar_path = os.path.join( 270 options.test_apk_jar_path = os.path.join(
270 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR, 271 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR,
271 '%s.jar' % options.test_apk) 272 '%s.jar' % options.test_apk)
272 273
273 return instrumentation_test_options.InstrumentationOptions( 274 return instrumentation_test_options.InstrumentationOptions(
274 options.build_type,
275 options.tool, 275 options.tool,
276 options.cleanup_test_files, 276 options.cleanup_test_files,
277 options.push_deps, 277 options.push_deps,
278 options.annotations, 278 options.annotations,
279 options.exclude_annotations, 279 options.exclude_annotations,
280 options.test_filter, 280 options.test_filter,
281 options.test_data, 281 options.test_data,
282 options.save_perf_json, 282 options.save_perf_json,
283 options.screenshot_failures, 283 options.screenshot_failures,
284 options.wait_for_debugger, 284 options.wait_for_debugger,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 options.uiautomator_jar = options.test_jar 333 options.uiautomator_jar = options.test_jar
334 else: 334 else:
335 options.uiautomator_jar = os.path.join( 335 options.uiautomator_jar = os.path.join(
336 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR, 336 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR,
337 '%s.dex.jar' % options.test_jar) 337 '%s.dex.jar' % options.test_jar)
338 options.uiautomator_info_jar = ( 338 options.uiautomator_info_jar = (
339 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] + 339 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] +
340 '_java.jar') 340 '_java.jar')
341 341
342 return uiautomator_test_options.UIAutomatorOptions( 342 return uiautomator_test_options.UIAutomatorOptions(
343 options.build_type,
344 options.tool, 343 options.tool,
345 options.cleanup_test_files, 344 options.cleanup_test_files,
346 options.push_deps, 345 options.push_deps,
347 options.annotations, 346 options.annotations,
348 options.exclude_annotations, 347 options.exclude_annotations,
349 options.test_filter, 348 options.test_filter,
350 options.test_data, 349 options.test_data,
351 options.save_perf_json, 350 options.save_perf_json,
352 options.screenshot_failures, 351 options.screenshot_failures,
353 options.uiautomator_jar, 352 options.uiautomator_jar,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 monkey tests. 399 monkey tests.
401 """ 400 """
402 if not options.package_name: 401 if not options.package_name:
403 error_func('Package name is required.') 402 error_func('Package name is required.')
404 403
405 category = options.category 404 category = options.category
406 if category: 405 if category:
407 category = options.category.split(',') 406 category = options.category.split(',')
408 407
409 return monkey_test_options.MonkeyOptions( 408 return monkey_test_options.MonkeyOptions(
410 options.build_type,
411 options.verbose_count, 409 options.verbose_count,
412 options.package_name, 410 options.package_name,
413 options.activity_name, 411 options.activity_name,
414 options.event_count, 412 options.event_count,
415 category, 413 category,
416 options.throttle, 414 options.throttle,
417 options.seed, 415 options.seed,
418 options.extra_args) 416 options.extra_args)
419 417
420 418
421 def _RunGTests(options, error_func): 419 def _RunGTests(options, error_func):
422 """Subcommand of RunTestsCommands which runs gtests.""" 420 """Subcommand of RunTestsCommands which runs gtests."""
423 ProcessGTestOptions(options) 421 ProcessGTestOptions(options)
424 422
425 exit_code = 0 423 exit_code = 0
426 for suite_name in options.suite_name: 424 for suite_name in options.suite_name:
427 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for 425 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for
428 # the gtest command. 426 # the gtest command.
429 gtest_options = gtest_test_options.GTestOptions( 427 gtest_options = gtest_test_options.GTestOptions(
430 options.build_type,
431 options.tool, 428 options.tool,
432 options.cleanup_test_files, 429 options.cleanup_test_files,
433 options.push_deps, 430 options.push_deps,
434 options.test_filter, 431 options.test_filter,
435 options.test_arguments, 432 options.test_arguments,
436 options.timeout, 433 options.timeout,
437 suite_name) 434 suite_name)
438 runner_factory, tests = gtest_setup.Setup(gtest_options) 435 runner_factory, tests = gtest_setup.Setup(gtest_options)
439 436
440 results, test_exit_code = test_dispatcher.RunTests( 437 results, test_exit_code = test_dispatcher.RunTests(
441 tests, runner_factory, False, options.test_device, 438 tests, runner_factory, False, options.test_device,
442 shard=True, 439 shard=True,
443 build_type=options.build_type,
444 test_timeout=None, 440 test_timeout=None,
445 num_retries=options.num_retries) 441 num_retries=options.num_retries)
446 442
447 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: 443 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
448 exit_code = test_exit_code 444 exit_code = test_exit_code
449 445
450 report_results.LogFull( 446 report_results.LogFull(
451 results=results, 447 results=results,
452 test_type='Unit test', 448 test_type='Unit test',
453 test_package=suite_name, 449 test_package=suite_name,
454 build_type=options.build_type,
455 flakiness_server=options.flakiness_dashboard_server) 450 flakiness_server=options.flakiness_dashboard_server)
456 451
457 if os.path.isdir(constants.ISOLATE_DEPS_DIR): 452 if os.path.isdir(constants.ISOLATE_DEPS_DIR):
458 shutil.rmtree(constants.ISOLATE_DEPS_DIR) 453 shutil.rmtree(constants.ISOLATE_DEPS_DIR)
459 454
460 return exit_code 455 return exit_code
461 456
462 457
463 def _RunInstrumentationTests(options, error_func): 458 def _RunInstrumentationTests(options, error_func):
464 """Subcommand of RunTestsCommands which runs instrumentation tests.""" 459 """Subcommand of RunTestsCommands which runs instrumentation tests."""
465 instrumentation_options = ProcessInstrumentationOptions(options, error_func) 460 instrumentation_options = ProcessInstrumentationOptions(options, error_func)
466 461
467 results = base_test_result.TestRunResults() 462 results = base_test_result.TestRunResults()
468 exit_code = 0 463 exit_code = 0
469 464
470 if options.run_java_tests: 465 if options.run_java_tests:
471 runner_factory, tests = instrumentation_setup.Setup(instrumentation_options) 466 runner_factory, tests = instrumentation_setup.Setup(instrumentation_options)
472 467
473 test_results, exit_code = test_dispatcher.RunTests( 468 test_results, exit_code = test_dispatcher.RunTests(
474 tests, runner_factory, options.wait_for_debugger, 469 tests, runner_factory, options.wait_for_debugger,
475 options.test_device, 470 options.test_device,
476 shard=True, 471 shard=True,
477 build_type=options.build_type,
478 test_timeout=None, 472 test_timeout=None,
479 num_retries=options.num_retries) 473 num_retries=options.num_retries)
480 474
481 results.AddTestRunResults(test_results) 475 results.AddTestRunResults(test_results)
482 476
483 if options.run_python_tests: 477 if options.run_python_tests:
484 runner_factory, tests = host_driven_setup.InstrumentationSetup( 478 runner_factory, tests = host_driven_setup.InstrumentationSetup(
485 options.python_test_root, options.official_build, 479 options.python_test_root, options.official_build,
486 instrumentation_options) 480 instrumentation_options)
487 481
488 if tests: 482 if tests:
489 test_results, test_exit_code = test_dispatcher.RunTests( 483 test_results, test_exit_code = test_dispatcher.RunTests(
490 tests, runner_factory, False, 484 tests, runner_factory, False,
491 options.test_device, 485 options.test_device,
492 shard=True, 486 shard=True,
493 build_type=options.build_type,
494 test_timeout=None, 487 test_timeout=None,
495 num_retries=options.num_retries) 488 num_retries=options.num_retries)
496 489
497 results.AddTestRunResults(test_results) 490 results.AddTestRunResults(test_results)
498 491
499 # Only allow exit code escalation 492 # Only allow exit code escalation
500 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: 493 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
501 exit_code = test_exit_code 494 exit_code = test_exit_code
502 495
503 report_results.LogFull( 496 report_results.LogFull(
504 results=results, 497 results=results,
505 test_type='Instrumentation', 498 test_type='Instrumentation',
506 test_package=os.path.basename(options.test_apk), 499 test_package=os.path.basename(options.test_apk),
507 annotation=options.annotations, 500 annotation=options.annotations,
508 build_type=options.build_type,
509 flakiness_server=options.flakiness_dashboard_server) 501 flakiness_server=options.flakiness_dashboard_server)
510 502
511 return exit_code 503 return exit_code
512 504
513 505
514 def _RunUIAutomatorTests(options, error_func): 506 def _RunUIAutomatorTests(options, error_func):
515 """Subcommand of RunTestsCommands which runs uiautomator tests.""" 507 """Subcommand of RunTestsCommands which runs uiautomator tests."""
516 uiautomator_options = ProcessUIAutomatorOptions(options, error_func) 508 uiautomator_options = ProcessUIAutomatorOptions(options, error_func)
517 509
518 runner_factory, tests = uiautomator_setup.Setup(uiautomator_options) 510 runner_factory, tests = uiautomator_setup.Setup(uiautomator_options)
519 511
520 results, exit_code = test_dispatcher.RunTests( 512 results, exit_code = test_dispatcher.RunTests(
521 tests, runner_factory, False, options.test_device, 513 tests, runner_factory, False, options.test_device,
522 shard=True, 514 shard=True,
523 build_type=options.build_type,
524 test_timeout=None, 515 test_timeout=None,
525 num_retries=options.num_retries) 516 num_retries=options.num_retries)
526 517
527 report_results.LogFull( 518 report_results.LogFull(
528 results=results, 519 results=results,
529 test_type='UIAutomator', 520 test_type='UIAutomator',
530 test_package=os.path.basename(options.test_jar), 521 test_package=os.path.basename(options.test_jar),
531 annotation=options.annotations, 522 annotation=options.annotations,
532 build_type=options.build_type,
533 flakiness_server=options.flakiness_dashboard_server) 523 flakiness_server=options.flakiness_dashboard_server)
534 524
535 return exit_code 525 return exit_code
536 526
537 527
538 def _RunMonkeyTests(options, error_func): 528 def _RunMonkeyTests(options, error_func):
539 """Subcommand of RunTestsCommands which runs monkey tests.""" 529 """Subcommand of RunTestsCommands which runs monkey tests."""
540 monkey_options = ProcessMonkeyTestOptions(options, error_func) 530 monkey_options = ProcessMonkeyTestOptions(options, error_func)
541 531
542 runner_factory, tests = monkey_setup.Setup(monkey_options) 532 runner_factory, tests = monkey_setup.Setup(monkey_options)
543 533
544 results, exit_code = test_dispatcher.RunTests( 534 results, exit_code = test_dispatcher.RunTests(
545 tests, runner_factory, False, None, shard=False) 535 tests, runner_factory, False, None, shard=False)
546 536
547 report_results.LogFull( 537 report_results.LogFull(
548 results=results, 538 results=results,
549 test_type='Monkey', 539 test_type='Monkey',
550 test_package='Monkey', 540 test_package='Monkey')
551 build_type=options.build_type)
552 541
553 return exit_code 542 return exit_code
554 543
555 544
556 545
557 def RunTestsCommand(command, options, args, option_parser): 546 def RunTestsCommand(command, options, args, option_parser):
558 """Checks test type and dispatches to the appropriate function. 547 """Checks test type and dispatches to the appropriate function.
559 548
560 Args: 549 Args:
561 command: String indicating the command that was received to trigger 550 command: String indicating the command that was received to trigger
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 option_parser.error('Invalid command.') 674 option_parser.error('Invalid command.')
686 command = argv[1] 675 command = argv[1]
687 VALID_COMMANDS[command].add_options_func(option_parser) 676 VALID_COMMANDS[command].add_options_func(option_parser)
688 options, args = option_parser.parse_args(argv) 677 options, args = option_parser.parse_args(argv)
689 return VALID_COMMANDS[command].run_command_func( 678 return VALID_COMMANDS[command].run_command_func(
690 command, options, args, option_parser) 679 command, options, args, option_parser)
691 680
692 681
693 if __name__ == '__main__': 682 if __name__ == '__main__':
694 sys.exit(main(sys.argv)) 683 sys.exit(main(sys.argv))
OLDNEW
« build/android/pylib/constants.py ('K') | « build/android/pylib/utils/report_results.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698