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

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

Issue 2505713002: Switch monkey test to platform mode. (Closed)
Patch Set: Switch monkey test to platform mode. Created 4 years, 1 month 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 import argparse 9 import argparse
10 import collections 10 import collections
(...skipping 18 matching lines...) Expand all
29 from pylib import constants 29 from pylib import constants
30 from pylib.base import base_test_result 30 from pylib.base import base_test_result
31 from pylib.base import environment_factory 31 from pylib.base import environment_factory
32 from pylib.base import test_dispatcher 32 from pylib.base import test_dispatcher
33 from pylib.base import test_instance_factory 33 from pylib.base import test_instance_factory
34 from pylib.base import test_run_factory 34 from pylib.base import test_run_factory
35 from pylib.constants import host_paths 35 from pylib.constants import host_paths
36 from pylib.linker import setup as linker_setup 36 from pylib.linker import setup as linker_setup
37 from pylib.junit import setup as junit_setup 37 from pylib.junit import setup as junit_setup
38 from pylib.junit import test_dispatcher as junit_dispatcher 38 from pylib.junit import test_dispatcher as junit_dispatcher
39 from pylib.monkey import setup as monkey_setup
40 from pylib.monkey import test_options as monkey_test_options
41 from pylib.results import json_results 39 from pylib.results import json_results
42 from pylib.results import report_results 40 from pylib.results import report_results
43 41
44 42
45 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( 43 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join(
46 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) 44 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json'))
47 45
48 46
49 def AddCommonOptions(parser): 47 def AddCommonOptions(parser):
50 """Adds all common options to |parser|.""" 48 """Adds all common options to |parser|."""
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 '--coverage-dir', dest='coverage_dir', type=os.path.realpath, 414 '--coverage-dir', dest='coverage_dir', type=os.path.realpath,
417 help='Directory to store coverage info.') 415 help='Directory to store coverage info.')
418 AddCommonOptions(parser) 416 AddCommonOptions(parser)
419 417
420 418
421 def AddMonkeyTestOptions(parser): 419 def AddMonkeyTestOptions(parser):
422 """Adds monkey test options to |parser|.""" 420 """Adds monkey test options to |parser|."""
423 421
424 group = parser.add_argument_group('Monkey Test Options') 422 group = parser.add_argument_group('Monkey Test Options')
425 group.add_argument( 423 group.add_argument(
426 '--package', required=True, choices=constants.PACKAGE_INFO.keys(), 424 '--browser', required=True, choices=constants.PACKAGE_INFO.keys(),
427 metavar='PACKAGE', help='Package under test.') 425 metavar='BROWSER', help='Browser under test.')
428 group.add_argument( 426 group.add_argument(
429 '--event-count', default=10000, type=int, 427 '--event-count', default=10000, type=int,
430 help='Number of events to generate (default: %(default)s).') 428 help='Number of events to generate (default: %(default)s).')
431 group.add_argument( 429 group.add_argument(
432 '--category', default='', 430 '--category', nargs='*', dest='categories', default=[],
433 help='A list of allowed categories.') 431 help='A list of allowed categories. Monkey will only visit activities '
432 'that are listed with one of the specified categories.')
434 group.add_argument( 433 group.add_argument(
435 '--throttle', default=100, type=int, 434 '--throttle', default=100, type=int,
436 help='Delay between events (ms) (default: %(default)s). ') 435 help='Delay between events (ms) (default: %(default)s). ')
437 group.add_argument( 436 group.add_argument(
438 '--seed', type=int, 437 '--seed', type=int,
439 help=('Seed value for pseudo-random generator. Same seed value generates ' 438 help='Seed value for pseudo-random generator. Same seed value generates '
440 'the same sequence of events. Seed is randomized by default.')) 439 'the same sequence of events. Seed is randomized by default.')
441 group.add_argument( 440 group.add_argument(
442 '--extra-args', default='', 441 '--repeat', dest='repeat', type=int, default=0,
443 help=('String of other args to pass to the command verbatim.')) 442 help='Number of times to repeat the specified set of tests.')
444 443 group.add_argument(
444 '--break-on-failure', '--break_on_failure',
445 dest='break_on_failure', action='store_true',
446 help='Whether to break on failure.')
445 AddCommonOptions(parser) 447 AddCommonOptions(parser)
446 AddDeviceOptions(parser) 448 AddDeviceOptions(parser)
447 449
448 def ProcessMonkeyTestOptions(args):
449 """Processes all monkey test options.
450
451 Args:
452 args: argparse.Namespace object.
453
454 Returns:
455 A MonkeyOptions named tuple which contains all options relevant to
456 monkey tests.
457 """
458 # TODO(jbudorick): Handle this directly in argparse with nargs='+'
459 category = args.category
460 if category:
461 category = args.category.split(',')
462
463 # TODO(jbudorick): Get rid of MonkeyOptions.
464 return monkey_test_options.MonkeyOptions(
465 args.verbose_count,
466 args.package,
467 args.event_count,
468 category,
469 args.throttle,
470 args.seed,
471 args.extra_args)
472
473 450
474 def AddPerfTestOptions(parser): 451 def AddPerfTestOptions(parser):
475 """Adds perf test options to |parser|.""" 452 """Adds perf test options to |parser|."""
476 453
477 group = parser.add_argument_group('Perf Test Options') 454 group = parser.add_argument_group('Perf Test Options')
478 455
479 class SingleStepAction(argparse.Action): 456 class SingleStepAction(argparse.Action):
480 def __call__(self, parser, namespace, values, option_string=None): 457 def __call__(self, parser, namespace, values, option_string=None):
481 if values and not namespace.single_step: 458 if values and not namespace.single_step:
482 parser.error('single step command provided, ' 459 parser.error('single step command provided, '
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 results=results, 575 results=results,
599 test_type='JUnit', 576 test_type='JUnit',
600 test_package=args.test_suite) 577 test_package=args.test_suite)
601 578
602 if args.json_results_file: 579 if args.json_results_file:
603 json_results.GenerateJsonResultsFile([results], args.json_results_file) 580 json_results.GenerateJsonResultsFile([results], args.json_results_file)
604 581
605 return exit_code 582 return exit_code
606 583
607 584
608 def _RunMonkeyTests(args, devices):
609 """Subcommand of RunTestsCommands which runs monkey tests."""
610 monkey_options = ProcessMonkeyTestOptions(args)
611
612 runner_factory, tests = monkey_setup.Setup(monkey_options)
613
614 results, exit_code = test_dispatcher.RunTests(
615 tests, runner_factory, devices, shard=False, test_timeout=None,
616 num_retries=args.num_retries)
617
618 report_results.LogFull(
619 results=results,
620 test_type='Monkey',
621 test_package='Monkey')
622
623 if args.json_results_file:
624 json_results.GenerateJsonResultsFile([results], args.json_results_file)
625
626 return exit_code
627
628
629 def _RunPythonTests(args): 585 def _RunPythonTests(args):
630 """Subcommand of RunTestsCommand which runs python unit tests.""" 586 """Subcommand of RunTestsCommand which runs python unit tests."""
631 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name] 587 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name]
632 suite_path = suite_vars['path'] 588 suite_path = suite_vars['path']
633 suite_test_modules = suite_vars['test_modules'] 589 suite_test_modules = suite_vars['test_modules']
634 590
635 sys.path = [suite_path] + sys.path 591 sys.path = [suite_path] + sys.path
636 try: 592 try:
637 suite = unittest.TestSuite() 593 suite = unittest.TestSuite()
638 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m) 594 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
(...skipping 29 matching lines...) Expand all
668 'Did not find device %s among attached device. Attached devices: %s' 624 'Did not find device %s among attached device. Attached devices: %s'
669 % (test_device, ', '.join(attached_devices))) 625 % (test_device, ', '.join(attached_devices)))
670 return test_device 626 return test_device
671 627
672 else: 628 else:
673 if not attached_devices: 629 if not attached_devices:
674 raise device_errors.NoDevicesError() 630 raise device_errors.NoDevicesError()
675 return sorted(attached_devices) 631 return sorted(attached_devices)
676 632
677 633
678 _DEFAULT_PLATFORM_MODE_TESTS = ['gtest', 'instrumentation', 'perf'] 634 _DEFAULT_PLATFORM_MODE_TESTS = ['gtest', 'instrumentation', 'monkey', 'perf']
679 635
680 636
681 def RunTestsCommand(args): # pylint: disable=too-many-return-statements 637 def RunTestsCommand(args): # pylint: disable=too-many-return-statements
682 """Checks test type and dispatches to the appropriate function. 638 """Checks test type and dispatches to the appropriate function.
683 639
684 Args: 640 Args:
685 args: argparse.Namespace object. 641 args: argparse.Namespace object.
686 642
687 Returns: 643 Returns:
688 Integer indicated exit code. 644 Integer indicated exit code.
(...skipping 19 matching lines...) Expand all
708 # pylint: enable=protected-access 664 # pylint: enable=protected-access
709 665
710 def get_devices(): 666 def get_devices():
711 return _GetAttachedDevices(args.blacklist_file, args.test_device, 667 return _GetAttachedDevices(args.blacklist_file, args.test_device,
712 args.enable_device_cache, args.num_retries) 668 args.enable_device_cache, args.num_retries)
713 669
714 if command == 'linker': 670 if command == 'linker':
715 return _RunLinkerTests(args, get_devices()) 671 return _RunLinkerTests(args, get_devices())
716 elif command == 'junit': 672 elif command == 'junit':
717 return _RunJUnitTests(args) 673 return _RunJUnitTests(args)
718 elif command == 'monkey':
719 return _RunMonkeyTests(args, get_devices())
720 elif command == 'python': 674 elif command == 'python':
721 return _RunPythonTests(args) 675 return _RunPythonTests(args)
722 else: 676 else:
723 raise Exception('Unknown test type.') 677 raise Exception('Unknown test type.')
724 678
725 679
726 _SUPPORTED_IN_PLATFORM_MODE = [ 680 _SUPPORTED_IN_PLATFORM_MODE = [
727 # TODO(jbudorick): Add support for more test types. 681 # TODO(jbudorick): Add support for more test types.
728 'gtest', 682 'gtest',
729 'instrumentation', 683 'instrumentation',
730 'junit', 684 'junit',
685 'monkey',
731 'perf', 686 'perf',
732 ] 687 ]
733 688
734 689
735 def RunTestsInPlatformMode(args): 690 def RunTestsInPlatformMode(args):
736 691
737 def infra_error(message): 692 def infra_error(message):
738 logging.fatal(message) 693 logging.fatal(message)
739 sys.exit(constants.INFRA_EXIT_CODE) 694 sys.exit(constants.INFRA_EXIT_CODE)
740 695
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 if e.is_infra_error: 834 if e.is_infra_error:
880 return constants.INFRA_EXIT_CODE 835 return constants.INFRA_EXIT_CODE
881 return constants.ERROR_EXIT_CODE 836 return constants.ERROR_EXIT_CODE
882 except: # pylint: disable=W0702 837 except: # pylint: disable=W0702
883 logging.exception('Unrecognized error occurred.') 838 logging.exception('Unrecognized error occurred.')
884 return constants.ERROR_EXIT_CODE 839 return constants.ERROR_EXIT_CODE
885 840
886 841
887 if __name__ == '__main__': 842 if __name__ == '__main__':
888 sys.exit(main()) 843 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698